If code

G

Guest

In the below code "InqType" is a dropdown.
The reports needs to show only those files that match the field choosen in
the dropdown.
Could someone please help me.


If IsNull(Me.StartDate) Or IsNull(Me.EndDate) Then
MsgBox "You must enter a Start & Stop date."

ElseIf IsNull(Me.InqType) Then
MsgBox "You Must Enter an Inquiry Type."
Else
DoCmd.OpenReport stDocName, acPreview
End If
 
W

Wayne Morgan

What is the data type of the field in the drop down (combo box) that the
value is coming from? The code is the same, but the syntax changes slightly
depending on the data type.

Assuming a number data type:
DoCmd.OpenReport stDocName, acViewPreview,, "[FieldName]=" & Me.InqType

Assuming a text data type:
DoCmd.OpenReport stDocName, acViewPreview,, "[FieldName]=""" & Me.InqType &
""""

Put in the correct field name for the field you want to filter.
 
G

Guest

This is good if I have only one combo box...
And it does answer my question...

But I have to add two more combo boxes - so coding it in the DoCmd does not
seem likethe right place...

How would I add 2 more combo boxes????

Thanks

Wayne Morgan said:
What is the data type of the field in the drop down (combo box) that the
value is coming from? The code is the same, but the syntax changes slightly
depending on the data type.

Assuming a number data type:
DoCmd.OpenReport stDocName, acViewPreview,, "[FieldName]=" & Me.InqType

Assuming a text data type:
DoCmd.OpenReport stDocName, acViewPreview,, "[FieldName]=""" & Me.InqType &
""""

Put in the correct field name for the field you want to filter.

--
Wayne Morgan
MS Access MVP


Dan @BCBS said:
In the below code "InqType" is a dropdown.
The reports needs to show only those files that match the field choosen in
the dropdown.
Could someone please help me.


If IsNull(Me.StartDate) Or IsNull(Me.EndDate) Then
MsgBox "You must enter a Start & Stop date."

ElseIf IsNull(Me.InqType) Then
MsgBox "You Must Enter an Inquiry Type."
Else
DoCmd.OpenReport stDocName, acPreview
End If
 
D

Douglas J Steele

Hard-coding it in the DoCmd, as Wayne illustrated, may not be appropriate in
that case, but coding it for the DoCmd still probably is.

Dim strConstraint As String

strConstraint = "[InquiryType]=" & Me.InqType & " AND "& _
"[StartDate] = " & Format(Me.StartDate, "\#mm\/dd\/yyyy\#") & " AND "
_
"[EndDate] = " & Format(Me.EndDate, "\#mm\/dd\/yyyy\#")

DoCmd.OpenReport stDocName, acViewPreview,, strConstraint


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Dan @BCBS said:
This is good if I have only one combo box...
And it does answer my question...

But I have to add two more combo boxes - so coding it in the DoCmd does not
seem likethe right place...

How would I add 2 more combo boxes????

Thanks

Wayne Morgan said:
What is the data type of the field in the drop down (combo box) that the
value is coming from? The code is the same, but the syntax changes slightly
depending on the data type.

Assuming a number data type:
DoCmd.OpenReport stDocName, acViewPreview,, "[FieldName]=" & Me.InqType

Assuming a text data type:
DoCmd.OpenReport stDocName, acViewPreview,, "[FieldName]=""" & Me.InqType &
""""

Put in the correct field name for the field you want to filter.

--
Wayne Morgan
MS Access MVP


Dan @BCBS said:
In the below code "InqType" is a dropdown.
The reports needs to show only those files that match the field choosen in
the dropdown.
Could someone please help me.


If IsNull(Me.StartDate) Or IsNull(Me.EndDate) Then
MsgBox "You must enter a Start & Stop date."

ElseIf IsNull(Me.InqType) Then
MsgBox "You Must Enter an Inquiry Type."
Else
DoCmd.OpenReport stDocName, acPreview
End If
 
G

Guest

I did not explain very good...
Everything Wayne explained is fine: But, now I need to add another combo
boxe.

Taking what you suggested below and adding a combo box called "status"
This gives me a Compile Error..

What am I doing worng???


Dim strConstraint As String

strConstraint = "[TR_INQUIRYTYPE]=" & Me.InqType & " AND " & _
"[TR_STATUS] = " & Me.status

stDocName = "r_GroupBasic"
DoCmd.OpenReport stDocName, acViewPreview, , strConstraint





Douglas J Steele said:
Hard-coding it in the DoCmd, as Wayne illustrated, may not be appropriate in
that case, but coding it for the DoCmd still probably is.

Dim strConstraint As String

strConstraint = "[InquiryType]=" & Me.InqType & " AND "& _
"[StartDate] = " & Format(Me.StartDate, "\#mm\/dd\/yyyy\#") & " AND "
_
"[EndDate] = " & Format(Me.EndDate, "\#mm\/dd\/yyyy\#")

DoCmd.OpenReport stDocName, acViewPreview,, strConstraint


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Dan @BCBS said:
This is good if I have only one combo box...
And it does answer my question...

But I have to add two more combo boxes - so coding it in the DoCmd does not
seem likethe right place...

How would I add 2 more combo boxes????

Thanks

Wayne Morgan said:
What is the data type of the field in the drop down (combo box) that the
value is coming from? The code is the same, but the syntax changes slightly
depending on the data type.

Assuming a number data type:
DoCmd.OpenReport stDocName, acViewPreview,, "[FieldName]=" & Me.InqType

Assuming a text data type:
DoCmd.OpenReport stDocName, acViewPreview,, "[FieldName]=""" & Me.InqType &
""""

Put in the correct field name for the field you want to filter.

--
Wayne Morgan
MS Access MVP


In the below code "InqType" is a dropdown.
The reports needs to show only those files that match the field choosen in
the dropdown.
Could someone please help me.


If IsNull(Me.StartDate) Or IsNull(Me.EndDate) Then
MsgBox "You must enter a Start & Stop date."

ElseIf IsNull(Me.InqType) Then
MsgBox "You Must Enter an Inquiry Type."
Else
DoCmd.OpenReport stDocName, acPreview
End If
 
D

Douglas J Steele

When you get the Compile Error, what line is it complaining about? Does the
error have any other details in it?

I see your declaration for strConstraint. Have you declared stDocName as
well?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Dan @BCBS said:
I did not explain very good...
Everything Wayne explained is fine: But, now I need to add another combo
boxe.

Taking what you suggested below and adding a combo box called "status"
This gives me a Compile Error..

What am I doing worng???


Dim strConstraint As String

strConstraint = "[TR_INQUIRYTYPE]=" & Me.InqType & " AND " & _
"[TR_STATUS] = " & Me.status

stDocName = "r_GroupBasic"
DoCmd.OpenReport stDocName, acViewPreview, , strConstraint





Douglas J Steele said:
Hard-coding it in the DoCmd, as Wayne illustrated, may not be appropriate in
that case, but coding it for the DoCmd still probably is.

Dim strConstraint As String

strConstraint = "[InquiryType]=" & Me.InqType & " AND "& _
"[StartDate] = " & Format(Me.StartDate, "\#mm\/dd\/yyyy\#") & " AND "
_
"[EndDate] = " & Format(Me.EndDate, "\#mm\/dd\/yyyy\#")

DoCmd.OpenReport stDocName, acViewPreview,, strConstraint


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Dan @BCBS said:
This is good if I have only one combo box...
And it does answer my question...

But I have to add two more combo boxes - so coding it in the DoCmd
does
not
seem likethe right place...

How would I add 2 more combo boxes????

Thanks

:

What is the data type of the field in the drop down (combo box) that the
value is coming from? The code is the same, but the syntax changes slightly
depending on the data type.

Assuming a number data type:
DoCmd.OpenReport stDocName, acViewPreview,, "[FieldName]=" & Me.InqType

Assuming a text data type:
DoCmd.OpenReport stDocName, acViewPreview,, "[FieldName]=""" & Me.InqType &
""""

Put in the correct field name for the field you want to filter.

--
Wayne Morgan
MS Access MVP


In the below code "InqType" is a dropdown.
The reports needs to show only those files that match the field choosen in
the dropdown.
Could someone please help me.


If IsNull(Me.StartDate) Or IsNull(Me.EndDate) Then
MsgBox "You must enter a Start & Stop date."

ElseIf IsNull(Me.InqType) Then
MsgBox "You Must Enter an Inquiry Type."
Else
DoCmd.OpenReport stDocName, acPreview
End If
 
G

Guest

Yes, I have declared stDocName.

The Error says Compile error: Method or data member not found.
The "Me.InqType" is highlighted: But I don't understand why "InqType" is
correct...

strConstraint = "[TR_INQUIRYTYPE]=" & Me.InqType & " AND " & _
"[TR_STATUS] = " & Me.status


Thanks



Douglas J Steele said:
When you get the Compile Error, what line is it complaining about? Does the
error have any other details in it?

I see your declaration for strConstraint. Have you declared stDocName as
well?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Dan @BCBS said:
I did not explain very good...
Everything Wayne explained is fine: But, now I need to add another combo
boxe.

Taking what you suggested below and adding a combo box called "status"
This gives me a Compile Error..

What am I doing worng???


Dim strConstraint As String

strConstraint = "[TR_INQUIRYTYPE]=" & Me.InqType & " AND " & _
"[TR_STATUS] = " & Me.status

stDocName = "r_GroupBasic"
DoCmd.OpenReport stDocName, acViewPreview, , strConstraint





Douglas J Steele said:
Hard-coding it in the DoCmd, as Wayne illustrated, may not be appropriate in
that case, but coding it for the DoCmd still probably is.

Dim strConstraint As String

strConstraint = "[InquiryType]=" & Me.InqType & " AND "& _
"[StartDate] = " & Format(Me.StartDate, "\#mm\/dd\/yyyy\#") & " AND "
_
"[EndDate] = " & Format(Me.EndDate, "\#mm\/dd\/yyyy\#")

DoCmd.OpenReport stDocName, acViewPreview,, strConstraint


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


This is good if I have only one combo box...
And it does answer my question...

But I have to add two more combo boxes - so coding it in the DoCmd does
not
seem likethe right place...

How would I add 2 more combo boxes????

Thanks

:

What is the data type of the field in the drop down (combo box) that the
value is coming from? The code is the same, but the syntax changes
slightly
depending on the data type.

Assuming a number data type:
DoCmd.OpenReport stDocName, acViewPreview,, "[FieldName]=" & Me.InqType

Assuming a text data type:
DoCmd.OpenReport stDocName, acViewPreview,, "[FieldName]=""" &
Me.InqType &
""""

Put in the correct field name for the field you want to filter.

--
Wayne Morgan
MS Access MVP


In the below code "InqType" is a dropdown.
The reports needs to show only those files that match the field
choosen in
the dropdown.
Could someone please help me.


If IsNull(Me.StartDate) Or IsNull(Me.EndDate) Then
MsgBox "You must enter a Start & Stop date."

ElseIf IsNull(Me.InqType) Then
MsgBox "You Must Enter an Inquiry Type."
Else
DoCmd.OpenReport stDocName, acPreview
End If
 
D

Douglas J Steele

You're sure it's spelled correctly?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Dan @BCBS said:
Yes, I have declared stDocName.

The Error says Compile error: Method or data member not found.
The "Me.InqType" is highlighted: But I don't understand why "InqType" is
correct...

strConstraint = "[TR_INQUIRYTYPE]=" & Me.InqType & " AND " & _
"[TR_STATUS] = " & Me.status


Thanks



Douglas J Steele said:
When you get the Compile Error, what line is it complaining about? Does the
error have any other details in it?

I see your declaration for strConstraint. Have you declared stDocName as
well?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Dan @BCBS said:
I did not explain very good...
Everything Wayne explained is fine: But, now I need to add another combo
boxe.

Taking what you suggested below and adding a combo box called "status"
This gives me a Compile Error..

What am I doing worng???


Dim strConstraint As String

strConstraint = "[TR_INQUIRYTYPE]=" & Me.InqType & " AND " & _
"[TR_STATUS] = " & Me.status

stDocName = "r_GroupBasic"
DoCmd.OpenReport stDocName, acViewPreview, , strConstraint





:

Hard-coding it in the DoCmd, as Wayne illustrated, may not be appropriate in
that case, but coding it for the DoCmd still probably is.

Dim strConstraint As String

strConstraint = "[InquiryType]=" & Me.InqType & " AND "& _
"[StartDate] = " & Format(Me.StartDate, "\#mm\/dd\/yyyy\#") &
"
AND "
_
"[EndDate] = " & Format(Me.EndDate, "\#mm\/dd\/yyyy\#")

DoCmd.OpenReport stDocName, acViewPreview,, strConstraint


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


This is good if I have only one combo box...
And it does answer my question...

But I have to add two more combo boxes - so coding it in the DoCmd does
not
seem likethe right place...

How would I add 2 more combo boxes????

Thanks

:

What is the data type of the field in the drop down (combo box)
that
the
value is coming from? The code is the same, but the syntax changes
slightly
depending on the data type.

Assuming a number data type:
DoCmd.OpenReport stDocName, acViewPreview,, "[FieldName]=" & Me.InqType

Assuming a text data type:
DoCmd.OpenReport stDocName, acViewPreview,, "[FieldName]=""" &
Me.InqType &
""""

Put in the correct field name for the field you want to filter.

--
Wayne Morgan
MS Access MVP


In the below code "InqType" is a dropdown.
The reports needs to show only those files that match the field
choosen in
the dropdown.
Could someone please help me.


If IsNull(Me.StartDate) Or IsNull(Me.EndDate) Then
MsgBox "You must enter a Start & Stop date."

ElseIf IsNull(Me.InqType) Then
MsgBox "You Must Enter an Inquiry Type."
Else
DoCmd.OpenReport stDocName, acPreview
End If
 
G

Guest

Yes, it's the same as when I had it in the DoCmd...

DoCmd.OpenReport stDocName, acViewPreview, , "[TR_INQUIRYTYPE]=""" &
Me.InqType & """"

Douglas J Steele said:
You're sure it's spelled correctly?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Dan @BCBS said:
Yes, I have declared stDocName.

The Error says Compile error: Method or data member not found.
The "Me.InqType" is highlighted: But I don't understand why "InqType" is
correct...

strConstraint = "[TR_INQUIRYTYPE]=" & Me.InqType & " AND " & _
"[TR_STATUS] = " & Me.status


Thanks



Douglas J Steele said:
When you get the Compile Error, what line is it complaining about? Does the
error have any other details in it?

I see your declaration for strConstraint. Have you declared stDocName as
well?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


I did not explain very good...
Everything Wayne explained is fine: But, now I need to add another combo
boxe.

Taking what you suggested below and adding a combo box called "status"
This gives me a Compile Error..

What am I doing worng???


Dim strConstraint As String

strConstraint = "[TR_INQUIRYTYPE]=" & Me.InqType & " AND " & _
"[TR_STATUS] = " & Me.status

stDocName = "r_GroupBasic"
DoCmd.OpenReport stDocName, acViewPreview, , strConstraint





:

Hard-coding it in the DoCmd, as Wayne illustrated, may not be
appropriate in
that case, but coding it for the DoCmd still probably is.

Dim strConstraint As String

strConstraint = "[InquiryType]=" & Me.InqType & " AND "& _
"[StartDate] = " & Format(Me.StartDate, "\#mm\/dd\/yyyy\#") & "
AND "
_
"[EndDate] = " & Format(Me.EndDate, "\#mm\/dd\/yyyy\#")

DoCmd.OpenReport stDocName, acViewPreview,, strConstraint


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


This is good if I have only one combo box...
And it does answer my question...

But I have to add two more combo boxes - so coding it in the DoCmd
does
not
seem likethe right place...

How would I add 2 more combo boxes????

Thanks

:

What is the data type of the field in the drop down (combo box) that
the
value is coming from? The code is the same, but the syntax changes
slightly
depending on the data type.

Assuming a number data type:
DoCmd.OpenReport stDocName, acViewPreview,, "[FieldName]=" &
Me.InqType

Assuming a text data type:
DoCmd.OpenReport stDocName, acViewPreview,, "[FieldName]=""" &
Me.InqType &
""""

Put in the correct field name for the field you want to filter.

--
Wayne Morgan
MS Access MVP


In the below code "InqType" is a dropdown.
The reports needs to show only those files that match the field
choosen in
the dropdown.
Could someone please help me.


If IsNull(Me.StartDate) Or IsNull(Me.EndDate) Then
MsgBox "You must enter a Start & Stop date."

ElseIf IsNull(Me.InqType) Then
MsgBox "You Must Enter an Inquiry Type."
Else
DoCmd.OpenReport stDocName, acPreview
End If
 
D

Douglas J Steele

Sorry: nothing comes to mind.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Dan @BCBS said:
Yes, it's the same as when I had it in the DoCmd...

DoCmd.OpenReport stDocName, acViewPreview, , "[TR_INQUIRYTYPE]=""" &
Me.InqType & """"

Douglas J Steele said:
You're sure it's spelled correctly?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Dan @BCBS said:
Yes, I have declared stDocName.

The Error says Compile error: Method or data member not found.
The "Me.InqType" is highlighted: But I don't understand why "InqType" is
correct...

strConstraint = "[TR_INQUIRYTYPE]=" & Me.InqType & " AND " & _
"[TR_STATUS] = " & Me.status


Thanks



:

When you get the Compile Error, what line is it complaining about?
Does
the
error have any other details in it?

I see your declaration for strConstraint. Have you declared stDocName as
well?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


I did not explain very good...
Everything Wayne explained is fine: But, now I need to add another combo
boxe.

Taking what you suggested below and adding a combo box called "status"
This gives me a Compile Error..

What am I doing worng???


Dim strConstraint As String

strConstraint = "[TR_INQUIRYTYPE]=" & Me.InqType & " AND " & _
"[TR_STATUS] = " & Me.status

stDocName = "r_GroupBasic"
DoCmd.OpenReport stDocName, acViewPreview, , strConstraint





:

Hard-coding it in the DoCmd, as Wayne illustrated, may not be
appropriate in
that case, but coding it for the DoCmd still probably is.

Dim strConstraint As String

strConstraint = "[InquiryType]=" & Me.InqType & " AND "& _
"[StartDate] = " & Format(Me.StartDate,
"\#mm\/dd\/yyyy\#") &
"
AND "
_
"[EndDate] = " & Format(Me.EndDate, "\#mm\/dd\/yyyy\#")

DoCmd.OpenReport stDocName, acViewPreview,, strConstraint


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


This is good if I have only one combo box...
And it does answer my question...

But I have to add two more combo boxes - so coding it in the DoCmd
does
not
seem likethe right place...

How would I add 2 more combo boxes????

Thanks

:

What is the data type of the field in the drop down (combo
box)
that
the
value is coming from? The code is the same, but the syntax changes
slightly
depending on the data type.

Assuming a number data type:
DoCmd.OpenReport stDocName, acViewPreview,, "[FieldName]=" &
Me.InqType

Assuming a text data type:
DoCmd.OpenReport stDocName, acViewPreview,, "[FieldName]=""" &
Me.InqType &
""""

Put in the correct field name for the field you want to filter.

--
Wayne Morgan
MS Access MVP


In the below code "InqType" is a dropdown.
The reports needs to show only those files that match the field
choosen in
the dropdown.
Could someone please help me.


If IsNull(Me.StartDate) Or IsNull(Me.EndDate) Then
MsgBox "You must enter a Start & Stop date."

ElseIf IsNull(Me.InqType) Then
MsgBox "You Must Enter an Inquiry Type."
Else
DoCmd.OpenReport stDocName, acPreview
End If
 
W

Wayne Morgan

In one case you used the extra quotes and in the other you didn't. This
shouldn't cause a compile error though, it should be a runtime error when
the data type is wrong for the syntax. When you type "Me.", do you get the
Intellisense popping up with a list of objects when you type the period? It
should and the combo box should be listed there. Is it? If so, select the
combo box from there instead of typing it. Also, please copy and paste your
code (if you didn't already) instead of retyping it into the message. There
may be a typo in the code that you're inadvertently correcting as you write
the message.
 
G

Guest

We may be a little off track here - again the code you suggested works - The
issue is that I need to add another combo box...

""""" This Works:"""""

stDocName = "r_GroupBasic"
DoCmd.OpenReport stDocName, acViewPreview, , "[TR_INQUIRYTYPE]=""" &
Me.InqType & """"

""" This Does Not:""""
stDocName = "r_GroupBasic"
DoCmd.OpenReport stDocName, acViewPreview, , "[TR_INQUIRYTYPE]=" &
Me.InqType & " AND " & _ "[TR_STATUS] = " & Me.status


Thanks

Wayne Morgan said:
In one case you used the extra quotes and in the other you didn't. This
shouldn't cause a compile error though, it should be a runtime error when
the data type is wrong for the syntax. When you type "Me.", do you get the
Intellisense popping up with a list of objects when you type the period? It
should and the combo box should be listed there. Is it? If so, select the
combo box from there instead of typing it. Also, please copy and paste your
code (if you didn't already) instead of retyping it into the message. There
may be a typo in the code that you're inadvertently correcting as you write
the message.

--
Wayne Morgan
MS Access MVP


Dan @BCBS said:
Yes, it's the same as when I had it in the DoCmd...

DoCmd.OpenReport stDocName, acViewPreview, , "[TR_INQUIRYTYPE]=""" &
Me.InqType & """"
 
W

Wayne Morgan

They both ought to work. The first one's syntax would be for TR_INQUIRYTYPE
being a text data type. The second one's syntax would be for TR_INQUIRYTYPE
being a number data type. As I said, I would expect this to cause a run time
error when the data type was wrong, not a compile error.

A possible compile error is the underscore ( _ ) just prior to "[TR_STATUS]
=. The underscore would be to continue on another line. You aren't here. The
command continues on the same line.

--
Wayne Morgan
MS Access MVP


Dan @BCBS said:
We may be a little off track here - again the code you suggested works -
The
issue is that I need to add another combo box...

""""" This Works:"""""

stDocName = "r_GroupBasic"
DoCmd.OpenReport stDocName, acViewPreview, , "[TR_INQUIRYTYPE]=""" &
Me.InqType & """"

""" This Does Not:""""
stDocName = "r_GroupBasic"
DoCmd.OpenReport stDocName, acViewPreview, , "[TR_INQUIRYTYPE]=" &
Me.InqType & " AND " & _ "[TR_STATUS] = " & Me.status


Thanks

Wayne Morgan said:
In one case you used the extra quotes and in the other you didn't. This
shouldn't cause a compile error though, it should be a runtime error when
the data type is wrong for the syntax. When you type "Me.", do you get
the
Intellisense popping up with a list of objects when you type the period?
It
should and the combo box should be listed there. Is it? If so, select the
combo box from there instead of typing it. Also, please copy and paste
your
code (if you didn't already) instead of retyping it into the message.
There
may be a typo in the code that you're inadvertently correcting as you
write
the message.

--
Wayne Morgan
MS Access MVP


Dan @BCBS said:
Yes, it's the same as when I had it in the DoCmd...

DoCmd.OpenReport stDocName, acViewPreview, , "[TR_INQUIRYTYPE]=""" &
Me.InqType & """"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

MsgBox results 11
Debugger runs but unwanted 8
stLinkCriteria 3
Add Cases 1
Object doesnt support this property... 1
Multiple filters on form 3
Help with IF Statement 3
Code using list box and multi select option 8

Top