SQL Form Filter Issue

G

Guest

I've copied a form filter that I want to use with a report. I replaced the
names of the report I want it to filter only which works except it will ask
for a company name which is not part of my report. I can't find where it may
be looking for this particular field. This only happens when I select my
"Select Filter" button so I have a feeling there is a problem there but can't
figure it out. The debug comes up with the arrow pointing to

Reports![System Sales Forecast].Filter = strSQL
Reports![System Sales Forecast].FilterOn = True


Below is what I did:


Option Compare Database
Option Explicit
Private Sub Command28_Click()

Dim strSQL As String, intCounter As Integer
'Build SQL String
For intCounter = 1 To 5
If Me("Filter" & intCounter) <> "" Then
strSQL = strSQL & "[" & Me("Filter" & intCounter).Tag & "] " & " =
" & Chr(34) & Me("Filter" & intCounter) & Chr(34) & " And "
End If
Next

If strSQL <> "" Then
'Strip Last " And "
strSQL = Left(strSQL, (Len(strSQL) - 5))
'Set the Filter property
Reports![System Sales Forecast].Filter = strSQL
Reports![System Sales Forecast].FilterOn = True
End If

End Sub

Private Sub Command29_Click()

Dim intCouter As Integer

For intCouter = 1 To 5
Me("Filter" & intCouter) = ""
Next

End Sub



Private Sub Command30_Click()
DoCmd.Close acForm, Me.Form.Name
End Sub

Private Sub Form_Close()
DoCmd.Close acReport, "System Sales Forecast Report"
DoCmd.Restore
End Sub

Private Sub Form_Open(Cancel As Integer)
DoCmd.OpenReport "System Sales Forecast Report", A_PREVIEW
DoCmd.Maximize
End Sub
 
S

Sylvain Lafontaine

What is the value of the string strSQL and of the record source of the
report?

What's the name of your report, "[System Sales Forecast]" or "[System Sales
Forecast Report]" ?
 
G

Guest

Sylvain:

Thank you for your response. I corrected the "System Sales Forecast" but
I'm not sure what you mean by the value of the strSQL? I'm not an expert and
have no idea what this means.

I'm working through it and actually have found someone here that knows how
to do this.

Thanks so much for your response!

Deb.

Sylvain Lafontaine said:
What is the value of the string strSQL and of the record source of the
report?

What's the name of your report, "[System Sales Forecast]" or "[System Sales
Forecast Report]" ?

--
Sylvain Lafontaine, ing.
MVP - Technologies Virtual-PC
E-mail: http://cerbermail.com/?QugbLEWINF


Debbie said:
I've copied a form filter that I want to use with a report. I replaced
the
names of the report I want it to filter only which works except it will
ask
for a company name which is not part of my report. I can't find where it
may
be looking for this particular field. This only happens when I select my
"Select Filter" button so I have a feeling there is a problem there but
can't
figure it out. The debug comes up with the arrow pointing to

Reports![System Sales Forecast].Filter = strSQL
Reports![System Sales Forecast].FilterOn = True


Below is what I did:


Option Compare Database
Option Explicit
Private Sub Command28_Click()

Dim strSQL As String, intCounter As Integer
'Build SQL String
For intCounter = 1 To 5
If Me("Filter" & intCounter) <> "" Then
strSQL = strSQL & "[" & Me("Filter" & intCounter).Tag & "] " & " =
" & Chr(34) & Me("Filter" & intCounter) & Chr(34) & " And "
End If
Next

If strSQL <> "" Then
'Strip Last " And "
strSQL = Left(strSQL, (Len(strSQL) - 5))
'Set the Filter property
Reports![System Sales Forecast].Filter = strSQL
Reports![System Sales Forecast].FilterOn = True
End If

End Sub

Private Sub Command29_Click()

Dim intCouter As Integer

For intCouter = 1 To 5
Me("Filter" & intCouter) = ""
Next

End Sub



Private Sub Command30_Click()
DoCmd.Close acForm, Me.Form.Name
End Sub

Private Sub Form_Close()
DoCmd.Close acReport, "System Sales Forecast Report"
DoCmd.Restore
End Sub

Private Sub Form_Open(Cancel As Integer)
DoCmd.OpenReport "System Sales Forecast Report", A_PREVIEW
DoCmd.Maximize
End Sub
 

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