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

Error Trapping a Parameter Values Box. 1

Status
Not open for further replies.

JesseL

IS-IT--Management
Jul 29, 2002
59
US
Hello.. I made a Edit Information form based on a query. There is also a the main form where I have a command button that When it is clicked on the form, the user has to enter in the "Mrd Unit Number" to access this form. In the criteria section for the "Mrd Unit Number", i put [Please enter the mrd unit number].

I would like to error trap the value typed in the parameter value pop up box. I am assuming something in VBA i guess. This command button is called cmdOpenEditFrm. So when the user clicks on the command button this parameter value box will pop up and they have to enter the "Mrd Unit Number"(this can be a number from 1-200, or whatever)

If the user enters in "blah.. blah", and it isn't a Mrd Unit number,(This is where i want to error trap it) I would like to have a Message box that pops up and says "Sorry, You have to enter in the correct Mrd Unit Number".
 
Also, when the user enters in anything they want into that parameter box, the Edit Information form pops up blank because they did not enter a "Mrd Unit Number" that is in one of the records. I do not want the form to pop up if they do not enter a mrd unit number.

On the edit information form, i would like a command button called "cmdEditAnother" and i would like to error trap it the same way as the command button on the main form. Same code i am assuming, so thats no problem.. I hope :/

Does anyone know how to error trap this parameter value box if the user enters just anything?

I tried to be as descriptive as possible, i hope you professionals out there know what i am talking about.

thanks
ksharp
 
Access ain't my speciality but my guess is that you'll have problems error trapping that parameter box. Why not set up a very simple form that just holds a textbox and a "GO" button
Use the textbox text to populate the criteria for the query and use the GO button to perform any error trapping you want. Rgds
~Geoff~
 
It Seems logical to do that geoff. I'll try do figure it out. Thanks :)

ksharp
 
Geoff.. this is kinda foggy what u said "Use the textbox text to populate the criteria for the query".. Im not understanding that to the fullest. I tryed different ways, but i was unable to accomplish this task. Learning from scratch isn't pleasant :)

thanks
ksharp
 
That's ok - Once you have built the form, you can reference it......Right click in the Criteria line for the field you want to pass a parameter to. choose "Build" - this will pop up a little wizard. Double click on Forms, Double click on All Forms, Double click on the Your Form (whatever it's called). A set of possible objects should appear in the middle window. Just double click on the textbox name. The default property is value so no need to do anything with the right side window. You should see
[Textbox1] in the top window of the wizard after you have selected your textbox (where terxtbox1 is the name of your textbox)
Now, your query will reference whatever is entered into the textbox. I would suggest that you alos have a button so you can a: attach your error check code
b: Run the query from it using the doCmd RunQuery method
Hope this makes sense
Rgds
~Geoff~
 
On the new form i created, I have exactly what u said to do:

I have a textbox(unbound) that the user will have to type the number in to. They will know the number, thats not the problem.

i have a command button that will do the error trapping and that run the query. By clicking on this, and if they enter the correct value, it will show more detailed info about that record.

sorry geoff.. I not familiar with this "Right click in the Criteria line for the field you want to pass a parameter to" Im assuming u mean the unbound textbox i createdon the new form? or do i right click on the textbox in the main form?


 
No - the crieria for the query.
Stop me if I'm wrong.....
You have a query that populates a form yes ??
go to the query and open it in design mode
You have a field called Mrd Unit Number yes ??
The 5th line in the query design view is called criteria - this is, I presume where you had [Please Enter Mrd Unit Number] as your prompt box
Instead of the prompt, you want to pass the value of the textbox on the form, so.....
Right click in the crieria pane for Mrd Unit Number
Choose Build
Double click on Forms
Double Click All Forms
Double Click YourFormName
Double Click on the textbox name in the MIDDLE window
(Left window is where the main objects are (forms / tables etc, Middle window is sub objects(ie textboxes / combo boxes etc, Right window is sub object properties (value / text etc))
In the criteria pane, where you had [Please Enter Mrd Unit Number], you should now have =[Textbox1] where Textbox1 is your textbox name
Rgds
~Geoff~
 
Thanks geoff.. I forgot about that :)

there is no docmd.runquery in MS Access 2002

what should i use?
 
Apologies - it should be DoCmd.OPENQUERY - don't be fooled by "OPEN" - it runs the query
From Access Help:
The OpenQuery method carries out the OpenQuery action in Visual Basic. For more information on how the action and its arguments work, see the action topic.

Syntax

DoCmd.OpenQuery queryname[, view][, datamode]

The OpenQuery method has the following arguments.

Argument Description

queryname A string expression that's the valid name of a query in the current database.
If you execute Visual Basic code containing the OpenQuery method in a library database, Microsoft Access looks for the query with this name first in the library database, then in the current database.
view One of the following intrinsic constants:
acViewDesign
acViewNormal (default)
acViewPreview
If the queryname argument is the name of a select, crosstab, union, or pass-through query whose ReturnsRecords property is set to –1, acViewNormal displays the query's result set. If the queryname argument refers to an action, data-definition, or pass-through query whose ReturnsRecords property is set to 0, acViewNormal runs the query.
If you leave this argument blank, the default constant (acViewNormal) is assumed.
datamode One of the following intrinsic constants:
acAdd
acEdit (default)
acReadOnly
If you leave this argument blank, the default constant (acEdit) is assumed.
Remarks

If you specify the datamode argument and leave the view argument blank, you must include the view argument's comma. If you leave a trailing argument blank, don't use a comma following the last argument you specify.

hope everything is working now
Rgds
~Geoff~
 
No! my apologies for not grasping the concepts. Thanks geoff.. lol, I do not have any help files installed.

Ok.. instead of the all the records showing in the query, I would like all the records to show in my other form, where the user can edit this info. hmM

thanks
ksharp
 
Surely, if the form is based on the query, it'll have all the records associated with the Mrd Unit Number entered in the textbox ??
Flow is:
Textbox value in input Form determines criteria for query
Query runs and returns records.
Main form is based on query and shows all the records the query brings back....
Rgds
~Geoff~
 
Thanks alot geoff.. it works! :)

I appreciate the time you have given me...

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top