Hi,
Can someone tell me why I can't get this code to run through a command button. For some reason, I get a "Data Type Mismatch in criteria expression" error. I think it has to do with UPDATE line in my code. I think I have all my def'n set up. I've already declared my connection.
Private Sub cmdViewReport_Click()
Dim cnn As ADODB.Connection
Set cnn = CurrentProject.Connection
txtEndDate.SetFocus
strEndDate = txtEndDate.Text
txtStartDate.SetFocus
strStartDate = txtStartDate.Text
If IsDate(strStartDate) = False Or _
IsDate(strEndDate) = False Then
MsgBox "Ship date fields must be valid dates", vbCritical + vbOKOnly
Else
gblShipDateFrom = strStartDate
gblShipDateTo = strEndDate
End If
cmdViewReport.Enabled = False
strSql = "sp_NOPickList " & "'" & strStartDate & "', '" & strEndDate & "'"
Set qd = CurrentDb.QueryDefs("sp_NOPickList"
qd.SQL = strSql
qd.Close
cnn.Execute "UPDATE tbl_NOHeader SET Printed = (Printed + 1) WHERE ShipDate BETWEEN '" & strStartDate & "' AND '" & strEndDate & "'"
DoCmd.RunMacro "mcr_NOPickList.ViewReport"
cmdViewReport.Enabled = True
Exit Sub
Can someone tell me why I can't get this code to run through a command button. For some reason, I get a "Data Type Mismatch in criteria expression" error. I think it has to do with UPDATE line in my code. I think I have all my def'n set up. I've already declared my connection.
Private Sub cmdViewReport_Click()
Dim cnn As ADODB.Connection
Set cnn = CurrentProject.Connection
txtEndDate.SetFocus
strEndDate = txtEndDate.Text
txtStartDate.SetFocus
strStartDate = txtStartDate.Text
If IsDate(strStartDate) = False Or _
IsDate(strEndDate) = False Then
MsgBox "Ship date fields must be valid dates", vbCritical + vbOKOnly
Else
gblShipDateFrom = strStartDate
gblShipDateTo = strEndDate
End If
cmdViewReport.Enabled = False
strSql = "sp_NOPickList " & "'" & strStartDate & "', '" & strEndDate & "'"
Set qd = CurrentDb.QueryDefs("sp_NOPickList"
qd.SQL = strSql
qd.Close
cnn.Execute "UPDATE tbl_NOHeader SET Printed = (Printed + 1) WHERE ShipDate BETWEEN '" & strStartDate & "' AND '" & strEndDate & "'"
DoCmd.RunMacro "mcr_NOPickList.ViewReport"
cmdViewReport.Enabled = True
Exit Sub