date and string condition with docmd.openform (1 Viewer)

otrivine

New member
Local time
Today, 12:21
Joined
Nov 8, 2011
Messages
7
hello there ,


can anyone tell what is wrong with this code:mad:? :

DoCmd.OpenForm "multiuseform", , , "([Dateofentry] = #" & Me![text1] & "#) And ([typeoffood] = " & Me!combo1 & ")"


thanks in advanced

dateofentry is DATE
typeoffood is STRING
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 12:21
Joined
Aug 30, 2003
Messages
36,125
The string value needs to be surrounded by ' just like the date value is surrounded by #.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 20:21
Joined
Sep 12, 2006
Messages
15,656
looks OK - not checked, whether the arguments are in the correct places.

the other thing is that you may need to format the date, as otherwise it may be treated as a US date. - so not text1 but

format(text1,"long date")
 

John Big Booty

AWF VIP
Local time
Tomorrow, 05:21
Joined
Aug 29, 2005
Messages
8,263
As pbaldy says try;

Code:
DoCmd.OpenForm "multiuseform", , , "[Dateofentry] = #" & Me![text1] & "# And [typeoffood] = [COLOR="Red"]'[/COLOR]" & Me!combo1 & "[COLOR="Red"]'[/COLOR]"
 

manusri

Registered User.
Local time
Today, 12:21
Joined
Dec 31, 2012
Messages
29
Hi all,
I learnt a lot from this thread and decided to implement the change.
But, I seem to get a syntax error for it. See below.
Code:
DoCmd.OpenReport "ReportName", acViewReport, , [Query].[QueryVariable] = '" & [Forms]![Front Page]![VarName] & "'"

Help Me Please!!!
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 12:21
Joined
Aug 30, 2003
Messages
36,125
You missed the quotes at the start of the criteria.
 

asadkhan

Registered User.
Local time
Today, 20:21
Joined
Oct 26, 2019
Messages
52
Hi
Can somebody help me,
I am trying combine following two fields in ms access vba,

Private Sub Command6_Click()

DoCmd.OpenForm "frmRecordbetweenTwoDatesbyDoctorNameFormView", , , "dtDate between #" & Format([ApptStartDate], "dd-mmm-yyyy") & "# And #" & Format([ApptEndDate], "dd-mmm-yyyy") & "# And [txtConsultantDoctorName] = '" & Me.CBODocName & "'"

DoCmd.RunCommand acCmdSaveRecord
DoCmd.Close acForm, "frmSearchAppointmentsBetween2DatesBYDOCNAME", acSaveYes
End Sub
----------
I am actually trying to pass parameters from a form which contains start and end date and a combo box containing names. what actually I am trying is looking up doctors' appointments between two dates with their names (doctor name). I am able to search them separately.

I am new to vba

I get following error:
Run-Time error '2501':
The OpenFormaction was canceled.

and if I implement following

DoCmd.OpenForm "frmRecordbetweenTwoDatesbyDoctorNameFormView", , , "dtDate between #" & Format([ApptStartDate], "dd-mmm-yyyy") & "# And #" & Format([ApptEndDate], "dd-mmm-yyyy") & "# " And " &[txtConsultantDoctorName] = '" & Me!CBODocName & "'"
code error becomes:
Run-Time error '13'
type mismatch
 

theDBguy

I’m here to help
Staff member
Local time
Today, 12:21
Joined
Oct 29, 2018
Messages
21,473
Hi asadkhan. Welcome to AWF! You might consider starting a new thread since this thread is a very old one.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 12:21
Joined
Oct 29, 2018
Messages
21,473
how do I do that
Go to the top of this thread and click on the Forms link in the breadcrumb. (Or, you can click on this link. On the new page, you should see the New Thread button towards the top-left corner. Click on it to start a new thread.
 

Users who are viewing this thread

Top Bottom