VBA finds string field in detail of report, not in group header

tad0075

Registered User.
Local time
Yesterday, 20:27
Joined
Jun 6, 2012
Messages
48
I'm making a simple code to open a detail report using a clicked text box as a filter. First part works fine, activated on click from the [Fee Description] text box in the header:

Code:
Private Sub Description_Click()

Dim Filter As String
Filter = Me.[Fee Description]
DoCmd.OpenReport "Tap and Hydrant Install Cost Detail", acViewPreview, , "[Fee Description] = '" & Filter & "'"

End Sub

I'm trying to expand this to include a subset as additional filter ([Fee Descriptoin] and [TAPSIZE]):

Code:
Private Sub TapSize_Click()

Dim Filter1 As String
Dim Filter2 As String
Filter2 = Me.TAPSIZE
Filter1 = Me.[Fee Description]
DoCmd.OpenReport "Tap and Hydrant Install Cost Detail", acViewPreview, ,  "[Fee Description] = '" & Filter1 & "' And [TAPSIZE] = '" &  Filter2 & "'"

End Sub

If I sub in a Fee Description directly into Filter1, the report opens just fine. It just keeps hanging up on me.[Fee Description] with run-time error 2465 - "Microsoft Office Access can't find the field 'Fee Description' referred to in your expression." Spelling is correct, copied identically from the working code above. What am I missing to be able to reference this field?

-Tyler
 
is the error occuring at Filter1 = Me.[Fee Description] or in the OpenReport command? If it is the OpenReport try brackets - you actually did this when you explained what you wanted to expand the criteria to do - I'm trying to expand this to include a subset as additional filter ([Fee Descriptoin] and [TAPSIZE]):

DoCmd.OpenReport "Tap and Hydrant Install Cost Detail", acViewPreview, , "(([Fee Description] = '" & Filter1 & "') And ([TAPSIZE] = '" & Filter2 & "'))"
 
Isskint -

Thanks for the quick reply. No, it appears to read the OpenReport command just fine. I subbed in a hard-coded string in the filter criteria (also deleted out Filter1 = Me.[Fee Description] for this) and had no problems. Stepping through the command, it's definitely not making it past "Filter1 = Me.[Fee Description]"

The only difference between TAPSIZE and Fee Description is that TAPSIZE is shown in the record with the embedded code, and Fee Description is only in the group header above it.

I'm sure I could plug Fee Description into the detail level and make it invisible if nothing else. Just seems like a messy way to accomplish this.

- Tyler
 

Users who are viewing this thread

Back
Top Bottom