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!

DoCmd.openform problem

Status
Not open for further replies.

NSNewey

Programmer
Jun 29, 2005
125
GB
Hi,

I need to extend the DoCmd.openForm statement so that I can also pass the user level and decide whether to allow the form to open.

I have written a sub which builds up a string containing the arguments that the DoCmd.openForm takes. (for example the string might end up being ‘fContact’, , , ‘[ContactID]=2’)

When I try to pass this string to the DoCmd.openForm statement, I get an error.

My statement would be DoCmd.openForm (strArgs)

Any ideas?

 
I've never tried using the OpenForm method passing a full string to it ... I don't think it will work, since Access will see the string as the first argument that is passed.

What you might want to try is separating the arguments into individual variables and then passing them, such as:

Code:
Dim strFormName As String
Dim strArgs As String

strFormName="fContact"
strArgs="[ContactID]=2"

DoCmd.OpenForm strFormName, , , strArgs

I think that'll do what you're attempting.

HTH,


Greg

"for me, the action is the juice.
 
Thanks,

I had thought about that... The problem is that there are 5 optional arguments which creates a nightmare because if one is null then you cannot pass it. Because any or all could be null I end up with 25 conditional statements. Building the string is much easier because if a particular argument is null I just add ", " to the end of the string then go to the next one.

Thanks anyway.
 
How are ya NSNewey . . .

Example call . . .
Code:
[blue]   Dim [purple][b]Build[/b][/purple] As String
   
   [purple][b]Build[/b][/purple] = "fContact,Tek-Tips,,,NSNewey,[ContactID]=2"
   DoCmd.OpenForm "[purple][b]FormName[/b][/purple]", acNormal, , , , , [purple][b]Build[/b][/purple][/blue]
. . . and in the [blue]OnOpen[/blue] event of the opened form:
Code:
[blue]   Dim Ary
   
   Ary = Split(Me.OpenArgs, ",")
   
   If Ary(4) <> "NSNewey" Then
      MsgBox "Can't Open Form!"
      Cancel = True
   End If[/blue]
[blue]Your Thoughts? . . .[/blue]

Calvin.gif
See Ya! . . . . . .
 
Thanks theAceMan1,

Cool solution...

openArgs are being used in a lot of cases already. As all users login and the login is stored in a global variable, I thought about using the on open event to test the user level. I hoped that if i could extend the openForm method it would save coding every forms open event but I think that is the only solution.

Also, I the split method is new to me and will be very useful elsewhere.

Cheers,

Neil.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top