Browseto and Wherecondition with multiple criteria (1 Viewer)

monfas

Registered User.
Local time
Today, 15:15
Joined
Jun 18, 2012
Messages
32
Hi,

I'm trying to get a report filtered and displayed inside a navigationform, using docmd.browseto to open the report. This report's recordset is a query and has a filed named donID (the ID number of a donor) to sort several donors. I'm using a listbox "lDonFil" to choose one or many donors.

If I filter with a combo box only one value, goes fine, the problem is when I try to put a string in the Where condition. It doesn't even work when I only choose one criteria (by only selecting one row in the lisbox lDonFil".

Does anyone have any idea where is the error? The code is bellow. I've tried several ways, with brackets, without brackets, etc...

Private Sub fltDonor_Click()

Dim ctlSource As Control
Dim strDonId As String
Dim intCurrentRow As Integer

Set ctlSource = Me.lDonFil

For intCurrentRow = 0 To ctlSource.ListCount - 1
If ctlSource.Selected(intCurrentRow) Then
strDonId = strDonId & ctlSource.Column(0, intCurrentRow) & " OR_
[DonId]="
End If
Next intCurrentRow

If Len(strDonId) < 13 Then
strDonId = ""
Else
strDonId = "[DonID]=" & Left(strDonId, Len(strDonId) - 12)
End If

DoCmd.BrowseTo acReport, "rDonor", "nmain.nmainsub>nreports.nreportprj>fparadonor.rparadonor", "strDonId", "",_ acFormReadOnly

End Sub

Thanks a lot if anyone can help
 

pr2-eugin

Super Moderator
Local time
Today, 13:15
Joined
Nov 30, 2011
Messages
8,494
monfas, for starters, you do not need to double quotes for the strDonId.. As it is a variable you are passing to the DoCmd function.. you just need it like..
Code:
DoCmd.BrowseTo acReport, "rDonor", "nmain.nmainsub>nreports.nreportprj>fparadonor.rpa radonor", [COLOR=Red][B]strDonId[/B][/COLOR], "", acFormReadOnly

PS: Please use Code Tags when posting VBA Code
 

monfas

Registered User.
Local time
Today, 15:15
Joined
Jun 18, 2012
Messages
32
Hi, I've tried with brackets, quotation marks, straight brackets, etc... and doesn't work. Thanks for the code tag tip. Any other sugestion?

thanks

Code:
Private Sub fltDonor_Click()

Dim ctlSource As Control
Dim strDonId As String
Dim intCurrentRow As Integer

Set ctlSource = Me.lDonFil

For intCurrentRow = 0 To ctlSource.ListCount - 1
If ctlSource.Selected(intCurrentRow) Then
strDonId = strDonId & ctlSource.Column(0, intCurrentRow) & " OR_
[DonId]="
End If
Next intCurrentRow

If Len(strDonId) < 13 Then
strDonId = ""
Else
strDonId = "[DonID]=" & Left(strDonId, Len(strDonId) - 12)
End If

DoCmd.BrowseTo acReport, "rDonor", "nmain.nmainsub>nreports.nreportprj>fparadonor.rpa radonor", strDonId, "",_ acFormReadOnly

End Sub
 

pr2-eugin

Super Moderator
Local time
Today, 13:15
Joined
Nov 30, 2011
Messages
8,494
Okay try a Debug.Print of the generated condition.. See if there is any problem with that.. Maybe no space between two conditions..
 

monfas

Registered User.
Local time
Today, 15:15
Joined
Jun 18, 2012
Messages
32
Thanks, After I wrote the line

Code:
Debug.Print strDonId

it started working... thanks

(all criteria where coming right as they should, but that happened also before, as I could see it when I was in debugging mode)

What happened here?
 

pr2-eugin

Super Moderator
Local time
Today, 13:15
Joined
Nov 30, 2011
Messages
8,494
Debug.Print does nothing but print whatever you want it to print in the immediate window (if you have not set it up to be seen, use CTRL+G).. Using Debug.Print will not have any programmatic influence except for debugging the problem..
 

Users who are viewing this thread

Top Bottom