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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cancelling a parameter value popform.

Status
Not open for further replies.

tamer64

IS-IT--Management
Aug 27, 2007
120
US
I have a MainForm. On the MainForm there is a button when clicked it opens a popup form "Form2". Form2 record source is a query and requires the user to enter a parameter value "[EmployeeID]" before opening and populating the form. The form works great, the parameter value form pops up and the user enters the EmployeeID number and the form opens. The problem is if the user cancels the paramter value I receive a runtime error "3021" which gives the user the option of debug and end. Is there anyway to bypass this error message so it does not appear if cancelled. This the code for the onclick event on the MainForm.

[blue]Private Sub GlobeEnter1_Click()
DoCmd.OpenQuery "004)_Deletes_T200_Table"
DoCmd.OpenQuery "005)_Makes_T200_Table"
DoCmd.OpenForm "Form2", acNormal [\blue]
 
go to the vb help and type "On Error" or google "error handling vb". It will show you how to set up error handling. In your error handler you will need some code like

If err.number = 3021 then
do something
else
msgbox Err.number & " " & Err.description
 
IMO, add a combo box to the form running the code so the user can select the employee ID from a combo box. Then use a little code to use a Where Condition clause in the DoCmd.OpenForm method.

faq701-6763

Code:
   'add error handling to trap for an error
   Dim strWhere as String
   Dim strForm as String
   strForm = "Form2"  ' or try even a better name
   strWhere = "1=1 "
   If Not IsNull(Me.cboEmpID) Then
       'assuming EmployeeID is a number
       strWhere = strWhere & " AND EmployeeID= " & Me.cboEmpID
   End If
   DoCmd.OpenForm strForm, , , strWhere


Duane
Hook'D on Access
MS Access MVP
 
Thank you Duane for the FAQ article-very interesting. I have since modifed my user input form and I now have a better understanding on when to use parameter input values.
:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top