Hi folks, need some help with this code, basically trying to identify if 2 fields within a table have been populated i.e.
Check date field and restaurant field, if these fields have been populated do
this
errStr = errStr & tmpDate & ", "
Else
validStr = validStr & tmpDate & ", "
stDocName = "McrReOrderDietPlanCRX"
DoCmd.RunMacro stDocName
End If
Code below, the If DCount("*" is comming up with a error, thanks in advance
####################################################################################
Private Sub Command37_Click()
Dim startDate As Date, endDate As Date, tmpDate As Date
Dim loopCtr As Long, dayCtr As Long, errStr As String, validStr As String
startDate = InputBox("Enter the Start Date")
endDate = InputBox("Enter the End Date")
dayCtr = DateDiff("d", startDate, endDate)
For loopCtr = 0 To dayCtr
tmpDate = DateAdd("d", loopCtr, startDate)
If DCount("*", "TblReOrderDate", "[ReOrderDate] = " & Format(tmpDate, "\#mm\/dd\/yyyy\#") <> 0 and "TblRestaurant", "[Restaurant] = "Watersidel") Then
errStr = errStr & tmpDate & ", "
Else
validStr = validStr & tmpDate & ", "
stDocName = "McrReOrderDietPlanCRX"
DoCmd.RunMacro stDocName
End If
Next
If Len(errStr & vbNullString) <> 0 Then
errStr = "Date(s) : " & Left(errStr, Len(errStr) - 2) & " already exists."
End If
If Len(validStr & vbNullString) <> 0 Then
validStr = "Date(s) : " & Left(validStr, Len(validStr) - 2) & " have been added."
End If
MsgBox errStr & validStr, vbInformation
End Sub
Check date field and restaurant field, if these fields have been populated do
this
errStr = errStr & tmpDate & ", "
Else
validStr = validStr & tmpDate & ", "
stDocName = "McrReOrderDietPlanCRX"
DoCmd.RunMacro stDocName
End If
Code below, the If DCount("*" is comming up with a error, thanks in advance
####################################################################################
Private Sub Command37_Click()
Dim startDate As Date, endDate As Date, tmpDate As Date
Dim loopCtr As Long, dayCtr As Long, errStr As String, validStr As String
startDate = InputBox("Enter the Start Date")
endDate = InputBox("Enter the End Date")
dayCtr = DateDiff("d", startDate, endDate)
For loopCtr = 0 To dayCtr
tmpDate = DateAdd("d", loopCtr, startDate)
If DCount("*", "TblReOrderDate", "[ReOrderDate] = " & Format(tmpDate, "\#mm\/dd\/yyyy\#") <> 0 and "TblRestaurant", "[Restaurant] = "Watersidel") Then
errStr = errStr & tmpDate & ", "
Else
validStr = validStr & tmpDate & ", "
stDocName = "McrReOrderDietPlanCRX"
DoCmd.RunMacro stDocName
End If
Next
If Len(errStr & vbNullString) <> 0 Then
errStr = "Date(s) : " & Left(errStr, Len(errStr) - 2) & " already exists."
End If
If Len(validStr & vbNullString) <> 0 Then
validStr = "Date(s) : " & Left(validStr, Len(validStr) - 2) & " have been added."
End If
MsgBox errStr & validStr, vbInformation
End Sub
Last edited: