What is wrong in the Code

sbaud2003

Member
Local time
Tomorrow, 03:28
Joined
Apr 5, 2020
Messages
184
Cnt = DCount("Mob", "QOCCUPATION", "DepartureDate = Me!sfrRoomOccupations.Form!DepartureDate")
 
Cnt = DCount("Mob", "QOCCUPATION", "DepartureDate = #" & Format$(Me!sfrRoomOccupations.Form!DepartureDate, "mm/dd/yyyy") & "#")
 
Cnt = DCount("Mob", "QOCCUPATION", "DepartureDate = #" & Format$(Me!sfrRoomOccupations.Form!DepartureDate, "mm/dd/yyyy") & "#")
Thank you sir, its parfectly working
Sir, if I put another condition
Cnt = DCount("*", "QOCCUPATION", "DepartureDate = #" & Format$(Me!sfrReservations.Form!DepartureDate, "mm/dd/yyyy") & "#" And [Mob] = Form!frmOccupants!TXTMOB)

frmOccupans is the Main form and Mob is number field, but error is coming
 
try:
Code:
Cnt = DCount("*", "QOCCUPATION", "DepartureDate = #" & _
Format$(Me!sfrReservations.Form!DepartureDate, "mm/dd/yyyy") & "# And [Mob] = " & Form!frmOccupants!TXTMOB)
 
Note: Format(DateValue, "mm/dd/yyyy") can build a string like 03.16.2024 (depend on date format ... / is the date separator in Format function).
=>
Format(DateValue, "mm\/dd\/yyyy") or with ISO format Format(DateValue, "yyyy-mm-dd")
 
Thank you sir, its parfectly working
Sir, if I put another condition
Cnt = DCount("*", "QOCCUPATION", "DepartureDate = #" & Format$(Me!sfrReservations.Form!DepartureDate, "mm/dd/yyyy") & "#" And [Mob] = Form!frmOccupants!TXTMOB)

frmOccupans is the Main form and Mob is number field, but error is coming
Put your criteria into a string variable, then debug.print it until you get it correct. Then you can use that in the function.
If you still cannot see your error, you can post the code and the output back here.
 
Last edited:
try:
Code:
Cnt = DCount("*", "QOCCUPATION", "DepartureDate = #" & _
Format$(Me!sfrReservations.Form!DepartureDate, "mm/dd/yyyy") & "# And [Mob] = " & Form!frmOccupants!TXTMOB)
thanks again,
output is coming 0, can you help
 
so there is 1 subform and another form frmOccupants?
 

Users who are viewing this thread

Back
Top Bottom