R
ryguy7272
I am using the below code to add records to a Table:
Option Compare Database
Private Sub AddRecord_Click()
Dim err As Integer
Dim cnn1 As ADODB.Connection
Dim rstcontact As ADODB.Recordset
Dim strCnn As String
If err < 1 Then
' Open a connection.
Set cnn1 = New ADODB.Connection
mydb = "C:\Search and Update.mdb"
strCnn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & mydb
cnn1.Open strCnn
' Open contact table.
Set rstcontact = New ADODB.Recordset
rstcontact.CursorType = adOpenKeyset
rstcontact.LockType = adLockOptimistic
rstcontact.Open "tblInternet", cnn1, , , adCmdTable
'get the new record data
rstcontact.AddNew
rstcontact!SiteName = txtSiteName
rstcontact!URL = txtURL
rstcontact!FirstName = txtFirstName
rstcontact!LastName = txtLastName
rstcontact!MiddleName = txtMiddleName
rstcontact!Title = txtTitle
rstcontact!Phone = txtPhone
rstcontact!SecondPhone = txtSecondPhone
rstcontact!Email = txtEmail
rstcontact!Fax = txtFax
rstcontact!Address1 = txtAddress1
rstcontact!Address2 = txtAddress2
rstcontact.Update
' Show the newly added data.
MsgBox "New contact: " & rstcontact!FirstName & " " &
rstcontact!LastName & " has been successfully added"
'close connections
rstcontact.Close
cnn1.Close
Else
MsgBox "An Error has occurred, please check and try again"
End If
End Sub
Code runs fine! I am only wondering how I can modify this to get the user’s
Login name and insert that into a Field in the table, along with some kind of
time and date stamp, so I know who is making the the updates to the Table and
when the updates were made.
Here, I can see the code for finding a UserName:
http://www.databasedev.co.uk/get_username_or_computername.html
But, how do I transfer that to the Table, instead of showing that in a Form?
Thanks!!
Ryan---
Option Compare Database
Private Sub AddRecord_Click()
Dim err As Integer
Dim cnn1 As ADODB.Connection
Dim rstcontact As ADODB.Recordset
Dim strCnn As String
If err < 1 Then
' Open a connection.
Set cnn1 = New ADODB.Connection
mydb = "C:\Search and Update.mdb"
strCnn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & mydb
cnn1.Open strCnn
' Open contact table.
Set rstcontact = New ADODB.Recordset
rstcontact.CursorType = adOpenKeyset
rstcontact.LockType = adLockOptimistic
rstcontact.Open "tblInternet", cnn1, , , adCmdTable
'get the new record data
rstcontact.AddNew
rstcontact!SiteName = txtSiteName
rstcontact!URL = txtURL
rstcontact!FirstName = txtFirstName
rstcontact!LastName = txtLastName
rstcontact!MiddleName = txtMiddleName
rstcontact!Title = txtTitle
rstcontact!Phone = txtPhone
rstcontact!SecondPhone = txtSecondPhone
rstcontact!Email = txtEmail
rstcontact!Fax = txtFax
rstcontact!Address1 = txtAddress1
rstcontact!Address2 = txtAddress2
rstcontact.Update
' Show the newly added data.
MsgBox "New contact: " & rstcontact!FirstName & " " &
rstcontact!LastName & " has been successfully added"
'close connections
rstcontact.Close
cnn1.Close
Else
MsgBox "An Error has occurred, please check and try again"
End If
End Sub
Code runs fine! I am only wondering how I can modify this to get the user’s
Login name and insert that into a Field in the table, along with some kind of
time and date stamp, so I know who is making the the updates to the Table and
when the updates were made.
Here, I can see the code for finding a UserName:
http://www.databasedev.co.uk/get_username_or_computername.html
But, how do I transfer that to the Table, instead of showing that in a Form?
Thanks!!
Ryan---