|
-
June 13th, 2001, 01:54 PM
#1
Creating a new record in an Access DB using Visual Basic
Hey all --
I'm having a problem finding the function to create a new record in an Access DB using the Click event of a command button. I have read the post about disconnecting and reconnecting to add a field, but i just need to know the way to add a record. Any help will be appreciated.
Thanks
-
June 13th, 2001, 03:49 PM
#2
Re: Creating a new record in an Access DB using Visual Basic
Using ADO..
Private Sub Command1_Click()
Dim Conn As ADODB.Connection
Dim sConn As String
Dim rs As ADODB.Recordset
Set Conn = New ADODB.Connection
sConn = "DSN=YourDSNNAME"
Conn.ConnectionString = sConn
Conn.CursorLocation = adUseServer
Conn.Open
Set rs = New ADODB.Recordset
rs.ActiveConnection = Conn
rs400.Open "SELECT * FROM YourTable", Conn, adOpenDynamic, adLockOptimistic
rs.Addnew
rs!FieldName1 = "your new value"
rs!FieldName2 = "your new value"
rs.Update
rs.close
Conn.close
Set rs = nothing
Set Conn = nothing
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|