Tomorrow's my final presentation of my DB and I ran into an unexpected problem: I access a main form called frmViewAllResou rces with several tabbed subforms through my switchboard. There's a preview and print button on the main form that generates a report called "Commoditie s." It previews and prints all the relevant fields from the main form and subform just fine.
On my switchboard, I can also access a form to print reports using a date range. My sample report "Commoditie s," which was auto-wizarded on tblResources (frmViewAllReso urces) worked just fine an hour ago. Then, I opened the report and started adding textboxes and comboboxes that linked to other forms (i.e. the subforms in frmViewAllResou rces). After flipping back to form view, all the boxes displayed the correct information for all 4 dummy records.
However, once I opened up the form to print reports by date range and selected "Commoditie s," the report opened up with "#Name?" in all fields. This is the code I'm using for my date range form:
Would anything here having anything to do with my form's phenomenon? Or, should I instead have my report's fields refer to the tables instead of the forms? Linking to the tables makes much more sense, so I'm going to try that. I apologize for not trying it before posting, but my time is limited so I'll need some ready advice if it doesn't work. Thanks.
On my switchboard, I can also access a form to print reports using a date range. My sample report "Commoditie s," which was auto-wizarded on tblResources (frmViewAllReso urces) worked just fine an hour ago. Then, I opened the report and started adding textboxes and comboboxes that linked to other forms (i.e. the subforms in frmViewAllResou rces). After flipping back to form view, all the boxes displayed the correct information for all 4 dummy records.
However, once I opened up the form to print reports by date range and selected "Commoditie s," the report opened up with "#Name?" in all fields. This is the code I'm using for my date range form:
Code:
Private Sub cmdPrintPreview_Click()
Dim strField As String 'Name of your date field.
Dim strWhere As String 'Where condition for OpenReport.
Const conDateFormat = "\#mm\/dd\/yyyy\#"
strField = "RecordDate"
If Not IsNull(cmbReports) And cmbReports <> "<select>" Then
If IsNull(Me.txtStartDate) Then
If Not IsNull(Me.txtEndDate) Then 'End date, but no start.
strWhere = strField & " <= " & Format(Me.txtEndDate, conDateFormat)
End If
Else
If IsNull(Me.txtEndDate) Then 'Start date, but no End.
strWhere = strField & " >= " & Format(Me.txtStartDate, conDateFormat)
Else 'Both start and end dates.
strWhere = strField & " Between " & Format(Me.txtStartDate, conDateFormat) _
& " And " & Format(Me.txtEndDate, conDateFormat)
End If
End If
Else
MsgBox ("You Must First Select a Report To Preview!")
cmbReports.SetFocus
End If
' Debug.Print strWhere 'For debugging purposes only.
DoCmd.OpenReport cmbReports, acViewPreview, , strWhere
End Sub
Comment