kryptonian
Board Regular
- Joined
- Oct 6, 2006
- Messages
- 104
I'm doing an attendance database with Excel as the entry form and Access as the database. My fields are:
| SAP_ID | LAST_NAME | GIVEN_NAME | TIME_IN | TIME_OUT |
Entering a new record is no problem if TIME_IN is still blank. But if TIME_IN is not blank, I want my code to edit that particular entry to add into TIME_OUT using the SAP_ID and TIME_IN to specify what record to edit. My code below.
*******************************************************
Sub cmdEdit()
Dim cn As ADODB.Connection
Dim cm As Command
Set cn = New ADODB.Connection
Set cm = New ADODB.Command
'On Error GoTo errHandler
cn.ConnectionString = "Provider = Microsoft.Jet.OleDb.4.0;" _
& "Data Source=C:\Users\v-edcepe\Documents\VBA Training Files\Attendance.mdb"
'sets the path for the connection
cn.Open 'opens the connection
Sheet2.Cells(4, 16) = "=now()"
cm.CommandText = "Update tblLog Set TIME_OUT = '" & Sheet2.Cells(4, 16) & "' where SAP_ID = '" & Sheet2.Cells(25, 3) & "' And TIME_IN='" & Sheet2.Cells(25, 6) & "'"
Set cm.ActiveConnection = cn
cm.Execute
cn.Close
'errHandler:
' MsgBox ("Data not found")
End Sub
*******************************************************
I purposely exluded errHandler for now so I know if my code is wrong.
I am getting a type mismatch error on the cm.CommandText line or cm.Execute if I edit it a bit.
Fields are setup properly in Access.
I'm using Windows 7 running Office 2007.
| SAP_ID | LAST_NAME | GIVEN_NAME | TIME_IN | TIME_OUT |
Entering a new record is no problem if TIME_IN is still blank. But if TIME_IN is not blank, I want my code to edit that particular entry to add into TIME_OUT using the SAP_ID and TIME_IN to specify what record to edit. My code below.
*******************************************************
Sub cmdEdit()
Dim cn As ADODB.Connection
Dim cm As Command
Set cn = New ADODB.Connection
Set cm = New ADODB.Command
'On Error GoTo errHandler
cn.ConnectionString = "Provider = Microsoft.Jet.OleDb.4.0;" _
& "Data Source=C:\Users\v-edcepe\Documents\VBA Training Files\Attendance.mdb"
'sets the path for the connection
cn.Open 'opens the connection
Sheet2.Cells(4, 16) = "=now()"
cm.CommandText = "Update tblLog Set TIME_OUT = '" & Sheet2.Cells(4, 16) & "' where SAP_ID = '" & Sheet2.Cells(25, 3) & "' And TIME_IN='" & Sheet2.Cells(25, 6) & "'"
Set cm.ActiveConnection = cn
cm.Execute
cn.Close
'errHandler:
' MsgBox ("Data not found")
End Sub
*******************************************************
I purposely exluded errHandler for now so I know if my code is wrong.
I am getting a type mismatch error on the cm.CommandText line or cm.Execute if I edit it a bit.
Fields are setup properly in Access.
I'm using Windows 7 running Office 2007.