chuckcoleman
Registered User.
- Local time
- Today, 00:21
- Joined
- Aug 20, 2010
- Messages
- 375
Hi,
I want to open a report and use one of two different queries based on the value of a field in a form.
In the code below UseTop100 looks at the value of a field using DLookUp on a form. Based on if that value if True I want to use the query "Startup Letter Query-2-Top100". If the value is False I want to use the query "Startup Letter Query-2". I don't get an errors and the report opens, but it doesn't have any records in either case. If I run the queries separately, there are records.
What am I doing wrong?
Thanks!
I want to open a report and use one of two different queries based on the value of a field in a form.
In the code below UseTop100 looks at the value of a field using DLookUp on a form. Based on if that value if True I want to use the query "Startup Letter Query-2-Top100". If the value is False I want to use the query "Startup Letter Query-2". I don't get an errors and the report opens, but it doesn't have any records in either case. If I run the queries separately, there are records.
What am I doing wrong?
Thanks!
Code:
Private Sub ViewStartupLetterX_Click()
'On Error GoTo ViewStartupLetterX_Click_Error
Dim UseTop100 As Boolean
Dim rpt As String
Dim strRecordSource As String
Dim rs100 As DAO.Recordset
Dim rsAll As DAO.Recordset
Dim db As DAO.Database
Set db = CurrentDb()
Set rs100 = db.OpenRecordset("Startup Letter Query-2-Top100")
Set rsAll = db.OpenRecordset("Startup Letter Query-2")
UseTop100 = DLookup("Top100", "Admin Table", "LimitNbr=1")
If UseTop100 = True Then
strRecordSource = rs100
ElseIf UseTop100 = False Then
strRecordSource = rsAll
End If
rpt = "Startup Customer Letter"
DoCmd.OpenReport rpt, acViewPreview, , strRecordSource
'Set rpt = Nothing
ViewStartupLetterX_Click_Exit:
Exit Sub
ViewStartupLetterX_Click_Error:
MsgBox Err.Description
Resume ViewStartupLetterX_Click_Exit
End Sub