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

otrivine

New member
Local time
Yesterday, 16:30
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
Yesterday, 16:30
Joined
Aug 30, 2003
Messages
35,684
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, 00:30
Joined
Sep 12, 2006
Messages
14,823
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
Today, 09:30
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
Yesterday, 16:30
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
Yesterday, 16:30
Joined
Aug 30, 2003
Messages
35,684
You missed the quotes at the start of the criteria.
 

asadkhan

Registered User.
Local time
Today, 00:30
Joined
Oct 26, 2019
Messages
40
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
Yesterday, 16:30
Joined
Oct 29, 2018
Messages
18,791
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
Yesterday, 16:30
Joined
Oct 29, 2018
Messages
18,791
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