date and string condition with docmd.openform

otrivine

New member
Local time
Today, 15:03
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
 
The string value needs to be surrounded by ' just like the date value is surrounded by #.
 
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")
 
As pbaldy says try;

Code:
DoCmd.OpenForm "multiuseform", , , "[Dateofentry] = #" & Me![text1] & "# And [typeoffood] = [COLOR="Red"]'[/COLOR]" & Me!combo1 & "[COLOR="Red"]'[/COLOR]"
 
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!!!
 
You missed the quotes at the start of the criteria.
 
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
 
Hi asadkhan. Welcome to AWF! You might consider starting a new thread since this thread is a very old one.
 
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

Back
Top Bottom