Hey.
I have a form which contains 5 textboxes which are pre-populated with some information from a table. Fundamentally, I want the user to be able to make some changes and save it to the table (without being bound in case they change there mind etc.).
I have some VBA script which runs when the user presses Save, however, I am struggling with date formats etc. I've tried many combinations of Format()s and # but to no avail. On the form, I have four textboxes which are populated with data indirectly from the table along with a "hidden" textbox with the primary ID (pID) to identify the record that needs updating.
At the moment, I keep getting a data type mismatch in criteria expression when I run the code. The textboxes are formatted as Short Date with _ placeholders, the table has a short date format as well, so I am a little clueless.
Has anyone got any ideas on how I can format this and get it to work?
Thank you
Edit: I should probably add, the data in the textboxes is retrieved from a listbox which is populated from another VBA query
My code currently sits as
Private Sub EditSave_Click()
Dim updateSQL As String
'check primary key is working
If Len(pID & vbNullString) = 0 Then
MsgBox "There was a problem with the primary key."
Exit Sub
End If
'check data isn't blank
If Len(editserial & vbNullString) = 0 _
Or Len(editactivity & vbNullString) = 0 _
Or Len(editRefDate & vbNullString) = 0 _
Or Len(EditExpiry & vbNullString) = 0 Then
MsgBox "Please enter all details"
Exit Sub
End If
'run sql
updateSQL = "UPDATE OnSite SET SerialNo = " & editserial & ", Activity = " & editactivity _
& ", RefDate = #Format(" & Me!editRefDate & ", ""dd/mm/yyyy"")#, ExpDate = #Format(" & Me!EditExpiry & ", ""dd/mm/yyyy"")#" _
& " WHERE [ID] = '" & Me!pID & "';"
MsgBox updateSQL
DoCmd.RunSQL (updateSQL)
'message user
MsgBox "Capsule added successfully"
End Sub
I have a form which contains 5 textboxes which are pre-populated with some information from a table. Fundamentally, I want the user to be able to make some changes and save it to the table (without being bound in case they change there mind etc.).
I have some VBA script which runs when the user presses Save, however, I am struggling with date formats etc. I've tried many combinations of Format()s and # but to no avail. On the form, I have four textboxes which are populated with data indirectly from the table along with a "hidden" textbox with the primary ID (pID) to identify the record that needs updating.
At the moment, I keep getting a data type mismatch in criteria expression when I run the code. The textboxes are formatted as Short Date with _ placeholders, the table has a short date format as well, so I am a little clueless.
Has anyone got any ideas on how I can format this and get it to work?
Thank you
Edit: I should probably add, the data in the textboxes is retrieved from a listbox which is populated from another VBA query
My code currently sits as
Private Sub EditSave_Click()
Dim updateSQL As String
'check primary key is working
If Len(pID & vbNullString) = 0 Then
MsgBox "There was a problem with the primary key."
Exit Sub
End If
'check data isn't blank
If Len(editserial & vbNullString) = 0 _
Or Len(editactivity & vbNullString) = 0 _
Or Len(editRefDate & vbNullString) = 0 _
Or Len(EditExpiry & vbNullString) = 0 Then
MsgBox "Please enter all details"
Exit Sub
End If
'run sql
updateSQL = "UPDATE OnSite SET SerialNo = " & editserial & ", Activity = " & editactivity _
& ", RefDate = #Format(" & Me!editRefDate & ", ""dd/mm/yyyy"")#, ExpDate = #Format(" & Me!EditExpiry & ", ""dd/mm/yyyy"")#" _
& " WHERE [ID] = '" & Me!pID & "';"
MsgBox updateSQL
DoCmd.RunSQL (updateSQL)
'message user
MsgBox "Capsule added successfully"
End Sub