Error passing qry to report

D

Debbie C

Newbie to VBA, inherited legacy app, trying to fix a few features that haven't worked for a while. Form passes parms to qry. Qry returns correct data but rpt always returns 0 rows.

gstrRecordSource is global

Private Sub cmdSearch_Click()
gstrRecordSource = "qryRateSearch"
'Qry works fine
'DoCmd.OpenQuery gstrRecordSource
DoCmd.OpenReport "rptRate", acViewPreview
gstrRecordSource = "qryRuleSearch"
DoCmd.OpenReport "rptRule", acViewPreview
gstrRecordSource = "qryLocationSearch"
DoCmd.OpenReport "rptLocation", acViewPreview
End Sub


Private Sub Report_Open(Cancel As Integer)
' Something wrong, always returns 0 records
Me.RecordSource = gstrRecordSource

' 1-8-09 D Chin
' Tried this but no change
' Suspect not picking up forms parms
'Dim strSQL As String, rs As DAO.Recordset
'strSQL = "SELECT * FROM " & gstrRecordSource
'Set rs = CurrentDb.OpenRecordset(strSQL)

End Sub

Greatly appreciate advice.

EggHeadCafe - .NET Developer Portal of Choice
http://www.eggheadcafe.com/default.aspx?ref=ng
 
C

Clifford Bass

Hi Debbie,

Where is gstrRecordSource defined? In a regular module or in the
form's module? If you put this line in the Report_Open sub at the top, what
do you get?

MsgBox "[" & gstrRecordSource & "]"

Clifford Bass
 

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