Report displays more groups than the one seleted (1 Viewer)

Punice

Registered User.
Local time
Today, 06:57
Joined
May 10, 2010
Messages
135
I submitted this earlier, but didn't receive any response(s).

My Access 2007 table holds 25 groups of trip records. The individual group records are sequentially numbered trip leg record sets, such as: 1.01, 1.02. . .etc. for the for as many legs for the first group, 2.01, 202...etc. for the second group and so on for all 25 groups.

Objective: Select any number from 1 to 25, from a combobox control's list, on a form, and open a report that displays all of the leg's records for that number (ie., trip).

Problem: When I select 1, for example, the report displays records (grouped) for 1, 10 thru 19 and when I pick 2, the report displays records for 2, 20 thru 25. However, when I pick 3 thru 9,
the reports display correctly, because of the 25 record limit. I want to be able to display only the records associated with the number that I pick.

Question: What additional code is required to facilitate what I want to happen in my routine shown below?
----------
Private Sub cboTrips_lbl_AfterUpdate()
Dim strReport As String
Dim lngView As Long

strReport = "rptTrips_By_TN" 'names the main report
T_TN = [Forms]![frmReport_Selector]![cboTrips_lbl] 'gets the trip number

'Close the report if already open: otherwise it won't filter properly.
If CurrentProject.AllReports(strReport).IsLoaded Then
DoCmd.Close acReport, strReport
End If

lngView = acViewPreview

'Open the report to display the selected trip group using DBGuy's code
DoCmd.OpenReport strReport, acViewPreview, , "[T_TN] Like '" & Me.cboTrips_lbl & "*'"
End Sub
----------
 

plog

Banishment Pending
Local time
Today, 05:57
Joined
May 11, 2011
Messages
11,613
Code:
"[T_TN] Like '" & Me.cboTrips_lbl & "*'"

Strings and numbers are technical terms, they mean specific things. You are not working with numbers with the above code. You are working with strings. So,

"1150" is like "1*"
"25" is like "2*"

The LIKE comparsion is a string compraison and is working perfectly, it's finding what its supposed to based on what you have told it to do. If you truly are working with numbers and want to compare numbers you must use their comparisons (=, >, <, >=, <=)
 

theDBguy

I’m here to help
Staff member
Local time
Today, 03:57
Joined
Oct 29, 2018
Messages
21,358
Hi. I think I told you if you want an exact match, then don't use Like, use = instead. Did that not help?
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 03:57
Joined
Aug 30, 2003
Messages
36,118
If it's a numeric field perhaps:

"Int([T_TN]) = " & Me.cboTrips_lbl

if it's text maybe

"[T_TN] Like '" & Me.cboTrips_lbl & ".*'"
 

Punice

Registered User.
Local time
Today, 06:57
Joined
May 10, 2010
Messages
135
I tried changing the T_Tn to an integer and a string & converted statement to open the report to match both recommendations, but the report still didn't show only 1 group.
It's the end of my day, here, and my brain is saturated. I'll try again, tomorrow.
I thank you, both, and learned some more about Access.
Appreciate you guidance.:)
 

theDBguy

I’m here to help
Staff member
Local time
Today, 03:57
Joined
Oct 29, 2018
Messages
21,358
As a last resort, maybe you can post a sample copy of your db with test data, so we can see what's happening. Just a thought...
 

Users who are viewing this thread

Top Bottom