help with code to open form with openargs

B

Barry A&P

I am now trying to clean up pages of messy code and i can do a lot of it with
a open form function
I am trying to add openargs to the openform function used in northwind..

i would like the code to open a form in whatever its default view may be if
open the strControlName is left out or ="" not sure how it has to be done.
and if a control is referenced get the value from that control and open the
form to a specific record.

currently the code locks up access and i have to restart.

heres what i have
Function OpenForms(strFormName As String, strcontrolname As String) As Integer
' This function is used in the Click event of command buttons that
' open forms on the Main Switchboard. Using a function is more efficient
' than repeating the same code in multiple event procedures.
' Use =OpenForms("Categories","me!snidcombo") in the controls event where
'categories is the name of the form and me!snidcombo would be the source for
openargs if needed
On Error GoTo Err_OpenForms

If CurrentProject.AllForms(strFormName).IsLoaded Then
DoCmd.Close acForm, strFormName
End If

If strcontrolname = "" Then
DoCmd.OpenForm strFormName
Else
DoCmd.OpenForm strFormName, , , , , , strcontrolname
End If

' Open specified form.
'old method DoCmd.OpenForm strFormName

Exit_OpenForms:
Exit Function

Err_OpenForms:
MsgBox Err.Description
Resume Exit_OpenForms

End Function

Thanks for any help
Barry
 
B

Barry A&P

Bruce
Thanks for your response

What does the arguement? Optional strcontrolname As String = "" change can
you elaborate on its use?

maybe i am just being difficult but i have a hundred comboboxes, buttons and
links that are used for navigation between records, forms, and reports. each
one was created using the wizard so there is 10 or so lines of code.
everytime i need to do a little VBA work in the editor i have to look through
pages of code to find what i am looking for. I was able to delete 30 of the
20 line private subs on my main switchboard with the OpenForm Function i
copied from the northwind sample's switchboard and the northwind comments say
its a more efficient method to use. (the sample in northwind returned an
integer i dont know why i just copied it.)

If i could get the function to also allow a optional control to be specified
to get a OpenArg value to pass on i could get rid of hundreds of lines of
code that basically all do the same thing,, either open a form or open a
form and pass a value to the openargs..
why not just use a line of code to open the form and
provide an OpenArgs value as needed?
do i need all of the error handling the wizard creates?

in the past i have always opened the control properties and on the event
used the codebuilder then everything is done on the VBA editor. instead of
having a privateSub created should i just use openform in the controls event
property

I am thouroughly enjoying access and i am trying to improve my technique.

if you have another suggestion i would be very open to it.

Thank you
Barry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top