Questions

Adding records in an access table using vb6

Tags:
+
0 Votes
Locked

Adding records in an access table using vb6

stogarepih
i am using developing an application in vb6 and have table in access and want to ypdate the tables from vb using the data control
.
i am requesting for code to add records in the tables from vb as well as validating the entries
before adding
  • +
    1 Votes
    stan

    Here is an example of adding a record to an Access table, and updating a record in Access. It requires an ODBC connection to the database.

    'Update Record
    Set cn = CreateObject("ADODB.Connection") '***'
    Set rs = CreateObject("adodb.recordset")
    cn.Open "db1.mdb", "Admin", "Password"

    strSQL = "UPDATE [T-Card Main] SET "
    If TextTrailer1.Text = "" Then
    strSQL = strSQL & "[Trailer Number] = Null "
    Else
    strSQL = strSQL & "[Trailer Number] = '" & TextTrailer1.Text & "' "
    End If
    strSQL = strSQL & "WHERE [Pronumber] = " & TextPronumber.Text
    Set rs = cn.Execute(strSQL)

    cn.Close


    'Add a new record
    Set cn = CreateObject("ADODB.Connection") '***'
    Set rs = CreateObject("adodb.recordset")
    cn.Open "db1.mdb", "Admin", "Password"

    varInsert1 = "INSERT INTO [EventLog] ([Pronumber], [Event], [EventDateTime], [EnteredBy]) "
    varInsert1 = varInsert1 & "VALUES (" & TextPronumber.Text & ", '" & "Order Entered" & "', "
    varInsert1 = varInsert1 & "#" & Now() & "#, '" & FormRTI.varUserName & "')"
    sSQL = varInsert1
    'MsgBox (sSQL)
    Set rs = cn.Execute(sSQL)

    cn.Close

    +
    1 Votes
    jose_m_hernandez

    Hi maybe this would help:

    name of the data control.recordset.addnew
    " ".recordest.update
    " ".edit

    and so on.

  • +
    1 Votes
    stan

    Here is an example of adding a record to an Access table, and updating a record in Access. It requires an ODBC connection to the database.

    'Update Record
    Set cn = CreateObject("ADODB.Connection") '***'
    Set rs = CreateObject("adodb.recordset")
    cn.Open "db1.mdb", "Admin", "Password"

    strSQL = "UPDATE [T-Card Main] SET "
    If TextTrailer1.Text = "" Then
    strSQL = strSQL & "[Trailer Number] = Null "
    Else
    strSQL = strSQL & "[Trailer Number] = '" & TextTrailer1.Text & "' "
    End If
    strSQL = strSQL & "WHERE [Pronumber] = " & TextPronumber.Text
    Set rs = cn.Execute(strSQL)

    cn.Close


    'Add a new record
    Set cn = CreateObject("ADODB.Connection") '***'
    Set rs = CreateObject("adodb.recordset")
    cn.Open "db1.mdb", "Admin", "Password"

    varInsert1 = "INSERT INTO [EventLog] ([Pronumber], [Event], [EventDateTime], [EnteredBy]) "
    varInsert1 = varInsert1 & "VALUES (" & TextPronumber.Text & ", '" & "Order Entered" & "', "
    varInsert1 = varInsert1 & "#" & Now() & "#, '" & FormRTI.varUserName & "')"
    sSQL = varInsert1
    'MsgBox (sSQL)
    Set rs = cn.Execute(sSQL)

    cn.Close

    +
    1 Votes
    jose_m_hernandez

    Hi maybe this would help:

    name of the data control.recordset.addnew
    " ".recordest.update
    " ".edit

    and so on.