Open Report based on a drop down box

  • Thread starter ielmrani via AccessMonster.com
  • Start date
I

ielmrani via AccessMonster.com

Hi,
I am using a form to run a report based on a combo box and it's working fine.


I select a name from the combo box , and click on a button to open the
filtered report.
I would like to add to the form 2 text boxes to do a search by dates also.

So, my form will have a combo box and 2 text boxes (for dates)

Here is the code I used and it' s working so far:

Private Sub Command8_Click()
Dim strWhere As String

If IsNull(Combo0) = False Then

strWhere = "ProvNm = '" & Combo0 & "'"

End If

DoCmd.OpenReport "Qrytest", acViewPreview, , strWhere

End Sub

Thanks in advance

Ismail
 
G

Guest

Something like this:

Private Sub Command8_Click()
Dim strWhere As String

If IsNull(Combo0) = False Then

strWhere = "ProvNm = '" & Combo0 & "'"

End If
If IsDate(txtStart) and IsDate(txtEnd) Then
strWhere = strWhere & " AND [MyDate] >= #" & txtStart & "# AND " & _
"[MyDate] <= #" & txtEnd & "#"
End If
DoCmd.OpenReport "Qrytest", acViewPreview, , strWhere

End Sub
 
M

Marshall Barton

ielmrani said:
I am using a form to run a report based on a combo box and it's working fine.

I select a name from the combo box , and click on a button to open the
filtered report.
I would like to add to the form 2 text boxes to do a search by dates also.

So, my form will have a combo box and 2 text boxes (for dates)

Here is the code I used and it' s working so far:

Private Sub Command8_Click()
Dim strWhere As String

If IsNull(Combo0) = False Then
strWhere = "ProvNm = '" & Combo0 & "'"
End If

DoCmd.OpenReport "Qrytest", acViewPreview, , strWhere
End Sub


Just add more If blocks of code and add " AND " for each
condition. Then general idea is something like this:

If IsNull(Combo0) = False Then
strWhere = " AND ProvNm = '" & Combo0 & "'"
End If

If IsNull(txtStart) = False Then
strWhere = " AND datefield >= " _
& Format(txtStart, "\#m\/d\/yyyy\#")
End If

If IsNull(txtEnd) = False Then
strWhere = " AND datefield <= " _
& Format(txtEnd, "\#m\/d\/yyyy\#")
End If

strWhere = Mid(strWhere, 6) 'dump extra AND
 
I

ielmrani via AccessMonster.com

Thank you so much guys, I wil try your suggestions and let you know.
Ismail
Marshall said:
I am using a form to run a report based on a combo box and it's working fine.
[quoted text clipped - 15 lines]
DoCmd.OpenReport "Qrytest", acViewPreview, , strWhere
End Sub

Just add more If blocks of code and add " AND " for each
condition. Then general idea is something like this:

If IsNull(Combo0) = False Then
strWhere = " AND ProvNm = '" & Combo0 & "'"
End If

If IsNull(txtStart) = False Then
strWhere = " AND datefield >= " _
& Format(txtStart, "\#m\/d\/yyyy\#")
End If

If IsNull(txtEnd) = False Then
strWhere = " AND datefield <= " _
& Format(txtEnd, "\#m\/d\/yyyy\#")
End If

strWhere = Mid(strWhere, 6) 'dump extra AND
 
I

ielmrani via AccessMonster.com

Beautiful. Both codes worked.
Again thank you so much

ismail

Marshall said:
I am using a form to run a report based on a combo box and it's working fine.
[quoted text clipped - 15 lines]
DoCmd.OpenReport "Qrytest", acViewPreview, , strWhere
End Sub

Just add more If blocks of code and add " AND " for each
condition. Then general idea is something like this:

If IsNull(Combo0) = False Then
strWhere = " AND ProvNm = '" & Combo0 & "'"
End If

If IsNull(txtStart) = False Then
strWhere = " AND datefield >= " _
& Format(txtStart, "\#m\/d\/yyyy\#")
End If

If IsNull(txtEnd) = False Then
strWhere = " AND datefield <= " _
& Format(txtEnd, "\#m\/d\/yyyy\#")
End If

strWhere = Mid(strWhere, 6) 'dump extra AND
 

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

Top