Question

Locked

Adding records in an access table using vb6

By 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

This conversation is currently closed to new comments.

3 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Answers

Collapse -

A VB6 example

by stan In reply to Adding records in an acce ...

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

Collapse -

Simple example

by jose_m_hernandez In reply to Adding records in an acce ...

Hi maybe this would help:

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

and so on.

Back to Software Forum
3 total posts (Page 1 of 1)  

Software Forums