I have been redesigning an old 1997 DB, which is actually very good.
The Setup: There is a form with a drop-down box filled with names that come from a table. After selecting a name you click a button which provides a graph (report). The graph is created from a query that also includes the same names as the drop-down box.
The Issue: I have added to the existing code so that when the button is clicked, it not only opens the graph, but now closes the form and views the report instead of previewing it. I did this so that I could place buttons to navigate between the reports and forms. But now I am asked to re-insert the drop-down name in order to populate the graph, which defeats the purpose of the drop-down box.
Here is the original code:
Code:
On Error GoTo Err_comcostbblgraph_Click
Dim stDocName As String
Dim cboboxtxt As String
stDocName = "Cost per bbl graph"
cboboxtxt = Me.cbofieldname.Value
If cboboxtxt = "" Then
Beep
MsgBox "Please select a field from the drop down list", vbOKOnly, "Select field"
Exit Sub
End If
DoCmd.OpenReport stDocName, acPreview
Exit_comcostbblgraph_Click:
Exit Sub
Err_comcostbblgraph_Click:
MsgBox Err.Description
Resume Exit_comcostbblgraph_Click
Here it is with my slight additions:
Code:
On Error GoTo Err_comcostbblgraph_Click
Dim stDocName As String
Dim cboboxtxt As String
Dim WellFilter As String
stDocName = "Cost per bbl graph"
cboboxtxt = Me.cbofieldname.Value
WellFilter = "frmwellfilter"
If cboboxtxt = "" Then
Beep
MsgBox "Please select a field from the drop down list", vbOKOnly, "Select field"
Exit Sub
End If
DoCmd.OpenReport stDocName, acViewReport
DoCmd.Close acForm, WellFilter
Exit_comcostbblgraph_Click:
Exit Sub
Err_comcostbblgraph_Click:
MsgBox Err.Description
Resume Exit_comcostbblgraph_Click
Once I change: DoCmd.OpenReport stDocName, acPreview
To: DoCmd.OpenReport stDocName, acViewReport
And I click the button on the form, I get this message: "Forms!frmwellfilter!cbofieldname"
Moreorless it's re-asking for the field name from the drop-down list. If it is re-put in, there is no problem (that I can tell). If I click OK or Cancel I get a blank table.
I know the message comes from the Criteria in the Field Name property of the query table it uses to populate the graph, but I can't figure out how to get it back to the way it was with my coding additions...
Any help would be greatly appreciated. Thank you.