What is wrong in the Code (1 Viewer)

sbaud2003

Member
Local time
Today, 12:55
Joined
Apr 5, 2020
Messages
178
Cnt = DCount("Mob", "QOCCUPATION", "DepartureDate = Me!sfrRoomOccupations.Form!DepartureDate")
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 15:25
Joined
May 7, 2009
Messages
19,245
Cnt = DCount("Mob", "QOCCUPATION", "DepartureDate = #" & Format$(Me!sfrRoomOccupations.Form!DepartureDate, "mm/dd/yyyy") & "#")
 

sbaud2003

Member
Local time
Today, 12:55
Joined
Apr 5, 2020
Messages
178
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
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 15:25
Joined
May 7, 2009
Messages
19,245
try:
Code:
Cnt = DCount("*", "QOCCUPATION", "DepartureDate = #" & _
Format$(Me!sfrReservations.Form!DepartureDate, "mm/dd/yyyy") & "# And [Mob] = " & Form!frmOccupants!TXTMOB)
 

Josef P.

Well-known member
Local time
Today, 09:25
Joined
Feb 2, 2023
Messages
827
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")
 

Gasman

Enthusiastic Amateur
Local time
Today, 08:25
Joined
Sep 21, 2011
Messages
14,310
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:

sbaud2003

Member
Local time
Today, 12:55
Joined
Apr 5, 2020
Messages
178
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
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 15:25
Joined
May 7, 2009
Messages
19,245
so there is 1 subform and another form frmOccupants?
 

Users who are viewing this thread

Top Bottom