Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MS Access Openform command

Status
Not open for further replies.

Jimmy211

Technical User
Aug 8, 2002
42
US
In a Purchase Order database I have 2 forms, one is my menu and one is a data entry form. On the Menu I have a button that uses the openform method to open the data entry form. I would like the button to prompt the user for the PO number to look up that PO. The following code seems to work:

stDocName = "PurchaseOrder"
DoCmd.OpenForm stDocName, , , "[PO_NUM] = PO_Number"

The problem I'm having is that if the user clicks on the Cancel button on the inputbox, they get the message "The Open Form Action was Canceled" and both forms wind up being closed. Is there a way to get the cancel button to open the Menu form again? Any help is greatly appreciated.

Jim
 
Hi Jim!

I didn't see any code there that would close the menu form but I will assume that you just didn't post it. Try this:

On Error GoTo ErrHandler

stDocName = "PurchaseOrder"
DoCmd.OpenForm stDocName, , , "[PO_NUM] = PO_Number"
Me.Close
Exit Sub

ErrHandler
If Err.Number <> 2001 Then
Resume Next
End If

Exit Sub

That will pop you out of the routine before you get to the Me.Close if the error is the cancelled action error.

hth
Jeff Bridgham
bridgham@purdue.edu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top