I am new to this posting stuff, but here is my current dilema . . . .
I have a checkbox in one of my tables and I need for it to update using an update query. Now using straight Access I can just say UPDATE tblname.checkboxfiled=Yes or even -1 and I get the good result.
The problem is I am using ome VBA coding and it doesn't seem to like the =Yes or =-1. I tried putting them in single quotes and I get a data conversion error.
My code is as follows:
Expand|Select|Wrap|Line Numbers
- Private Sub cmdRoleExists_Click()
- Dim DB As DAO.Database
- Dim qdf As DAO.QueryDef
- Dim varItem As Variant
- Dim strCriteria As String
- Dim strSQL As String
- Set DB = CurrentDb()
- Set qdf = DB.QueryDefs("qrySAPSecurityRoleExistsUpdate")
- For Each varItem In Me!lstSecuritySAP.ItemsSelected
- strCriteria = strCriteria & "," & Me!lstSecuritySAP.ItemData(varItem)
- Next varItem
- If Len(strCriteria) = 0 Then
- MsgBox "You must select at least 1 SAP #" _
- , vbExclamation, "No Selection Made"
- Exit Sub
- End If
- strCriteria = Right(strCriteria, Len(strCriteria) - 1)
- strSQL = "UPDATE tblTrackingData SET tblTrackingData.[SAP Security Role Status] = 'Completed - ' & Date(), tblTrackingData.[SAP Security Role] = Yes" & _
- "WHERE tblTrackingData.[SAP #] IN(" & strCriteria & ")"
- qdf.SQL = strSQL
- DoCmd.OpenQuery "qrySAPSecurityRoleExistsUpdate"
- Set DB = Nothing
- Set qdf = Nothing
- End Sub
Any thoughts would be most appreciated.
Thanks!