How to properly code and write in table vba?

Asked By 40 points N/A Posted on -


I am  a new Information Technology student and not so very familiar with VBA. Can anybody here give me the basic code to write in table VBA? Thank you.

Answered By 5 points N/A #131138

How to properly code and write in table vba?


From your question I can understand that you are very new to programming. You read some articles to understand OOP (Object Oriented Programming) first. Go through below link and you will understand the OOP concept.

Try some tutorials to get a basic understanding about programming. You are not a professional in one month but keep learning and leave it for the time.

Below method is written in VB.NET which will insert data into a SQL Server database.

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) //btnSave Button Click Event


        SqlConnection conn = New SqlConnection("server=.SQLEXPRESS;uid=sa;pwd=abc;database=dbBook")// Create Connection Object

        conn.Open()// Open connection

        SqlCommand cmd = New SqlCommand( _

        "INSERT INTO tblBook(BookCode, BookTitle) " & _

        "VALUES(@bookCode, @bookTitle)") // Create command object

        cmd.Connection = conn

        with cmd.Parameters

            .AddWithValue("bookCode", txtBookCode.Text)

            .AddWithValue("bookTitle", txtTitle.Text) //Add command parameters

             end with

        myCommand.ExecuteNonQuery() //Execute query

        MsgBox("The book named '" & txtTitle.Text & "' Added!") //Print message

        Catch ex As Exception


    End Try


End Sub

Login/Register to Answer

Related Questions