Hello all. I just found this forum; hopefully someone can help me with a problem I'm having.
I have a command button in a subform with VB code that executes upon clicking the button. The point of the code is to check a value on a table and determine which report should be opened. I'll post the code for reference:
******
Private Sub View_Reports_Click()
On Error GoTo Err_View_Reports_Click
Dim stDocName As String
'This code checks where the PSV vents to and opens the appropriate report form
Dim idTest As Variant
idTest = DLookup("[Vents To]", "PSV Data", "[Tag Number] = Forms![PSV Release Subform]![PSV Number]")
If idTest = 2 Or idTest = 3 Or idTest = 4 Or idTest = 15 Then
stDocName = "PSV Flare Release Subreport"
DoCmd.OpenReport stDocName, acPreview, , "[Record No] = Forms![Release Calculation Form]![Record No]"
Else
stDocName = "PSV Release Subreport"
DoCmd.OpenReport stDocName, acPreview, , "[Record No] = Forms![Release Calculation Form]![Record No]"
End If
Exit_View_Reports_Click:
Exit Sub
Err_View_Reports_Click:
MsgBox Err.Description
Resume Exit_View_Reports_Click
End Sub
******
The button is in subform "PSV Release Subform". When I click the button with just the subform open, it will prompt me for the value of "Forms![Release Calculation Form]![Record No]" since that form is not open. I can manually enter the value and the code will execute fine.
But if I open "Release Calculation Form" that has the "PSV Release Subform" in it, and click on the command button in the subform, I just get an Access error message box that says, "You canceled the previous operation." I would have expected the code to be able to find the value of "Forms![Release Calculation Form]![Record No]" and execute normally.
Does anyone know why the subform command button won't work when it is clicked in the main form?
Thanks in advance.
I have a command button in a subform with VB code that executes upon clicking the button. The point of the code is to check a value on a table and determine which report should be opened. I'll post the code for reference:
******
Private Sub View_Reports_Click()
On Error GoTo Err_View_Reports_Click
Dim stDocName As String
'This code checks where the PSV vents to and opens the appropriate report form
Dim idTest As Variant
idTest = DLookup("[Vents To]", "PSV Data", "[Tag Number] = Forms![PSV Release Subform]![PSV Number]")
If idTest = 2 Or idTest = 3 Or idTest = 4 Or idTest = 15 Then
stDocName = "PSV Flare Release Subreport"
DoCmd.OpenReport stDocName, acPreview, , "[Record No] = Forms![Release Calculation Form]![Record No]"
Else
stDocName = "PSV Release Subreport"
DoCmd.OpenReport stDocName, acPreview, , "[Record No] = Forms![Release Calculation Form]![Record No]"
End If
Exit_View_Reports_Click:
Exit Sub
Err_View_Reports_Click:
MsgBox Err.Description
Resume Exit_View_Reports_Click
End Sub
******
The button is in subform "PSV Release Subform". When I click the button with just the subform open, it will prompt me for the value of "Forms![Release Calculation Form]![Record No]" since that form is not open. I can manually enter the value and the code will execute fine.
But if I open "Release Calculation Form" that has the "PSV Release Subform" in it, and click on the command button in the subform, I just get an Access error message box that says, "You canceled the previous operation." I would have expected the code to be able to find the value of "Forms![Release Calculation Form]![Record No]" and execute normally.
Does anyone know why the subform command button won't work when it is clicked in the main form?
Thanks in advance.