Hi All,
I'm tired of Excel and constantly updating links in workbooks, so I'm linking tables to our SQL server in hopes of querying data to generate reports. After failed attempts trying to recreate examples from the FAQ section, I'm reaching out for help. Ultimately, I want to query a handful of joined tables based on parameters selected in my combo boxes and then generate a report, without using the built in wizards. For right now, I've simplified my select statement to select from only one table.
With the below code, I see the "Name?" error. I tried setting QueryDefs and that didn't work (obviously missing something). Then, I thought I would set the report RecordSource = to the strSQL variable and received the "Name?" error. Can someone help me understand what I'm missing and why the below code wouldn't work?
Additionally, I've added txt boxes to the report and set their respective control sources, in properties table in design view of the report, to the field names in the table that I'm querying. For example: =[UMONTH]
Private Sub cmd_RR_RE_Click()
Dim strSQL As String
Dim strWhere As String
strSQL = "SELECT * FROM dbo_TOTALS_RS "
If Not (Me.cboDate.Value = vbNullString) Then
If Len(strWhere) > 0 Then
strWhere = strWhere & " WHERE "
Else
strWhere = strWhere & " AND "
End If
strWhere = strWhere & " UMONTH = '" & Me.cboDate.Value & "'"
End If
If Not (Me.cboBook.Value = vbNullString) Then
If Len(strWhere) > 0 Then
strWhere = strWhere & " WHERE "
Else
strWhere = strWhere & " AND "
End If
strWhere = strWhere & " IBOOK = '" & Me.cboBook.Value & "'"
End If
strSQL = strSQL & strWhere
Debug.Print strSQL
Report_RE_Schedule.RecordSource = strSQL
DoCmd.OpenReport "RE_Schedule", acViewPreview
End Sub
I'm tired of Excel and constantly updating links in workbooks, so I'm linking tables to our SQL server in hopes of querying data to generate reports. After failed attempts trying to recreate examples from the FAQ section, I'm reaching out for help. Ultimately, I want to query a handful of joined tables based on parameters selected in my combo boxes and then generate a report, without using the built in wizards. For right now, I've simplified my select statement to select from only one table.
With the below code, I see the "Name?" error. I tried setting QueryDefs and that didn't work (obviously missing something). Then, I thought I would set the report RecordSource = to the strSQL variable and received the "Name?" error. Can someone help me understand what I'm missing and why the below code wouldn't work?
Additionally, I've added txt boxes to the report and set their respective control sources, in properties table in design view of the report, to the field names in the table that I'm querying. For example: =[UMONTH]
Private Sub cmd_RR_RE_Click()
Dim strSQL As String
Dim strWhere As String
strSQL = "SELECT * FROM dbo_TOTALS_RS "
If Not (Me.cboDate.Value = vbNullString) Then
If Len(strWhere) > 0 Then
strWhere = strWhere & " WHERE "
Else
strWhere = strWhere & " AND "
End If
strWhere = strWhere & " UMONTH = '" & Me.cboDate.Value & "'"
End If
If Not (Me.cboBook.Value = vbNullString) Then
If Len(strWhere) > 0 Then
strWhere = strWhere & " WHERE "
Else
strWhere = strWhere & " AND "
End If
strWhere = strWhere & " IBOOK = '" & Me.cboBook.Value & "'"
End If
strSQL = strSQL & strWhere
Debug.Print strSQL
Report_RE_Schedule.RecordSource = strSQL
DoCmd.OpenReport "RE_Schedule", acViewPreview
End Sub