How to properly code and write in table vba?
Â
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.
Â
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.
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.
https://www.codeproject.com/Articles/22769/Introduction-to-Object-Oriented-Programming-Concep
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
   Try
       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
       MsgBox(ex.Message())
   End Try
   myConnection.Close()
End Sub