quick code question

  • Thread starter Thread starter Pwyd
  • Start date Start date
P

Pwyd

Public Function AdminCheck()

Dim userID As String * 20
userID = GetUserID()

If userID = xxxxxx Or userID = xxxxxx1 Or userID = xxxxxx2 Or userID =
xxxxxx3 Then
DoCmd.RunMacro (toOpeningScreen)
Else
DoCmd.RunMacro(toOpeningScreenProcessor)

End If

End Function


Two questions:

Why does it give an error for the second DoCmd line?

If i wanted to call this function from startup, can i put that in the
Startup line in the
database Startup menu option, or do i need to make a hidden form that loads
the function in a macro?
 
Remove the parens and enclose the macro name in quotes.

Write back if that does not work.

PJ
 
It certainly does run, it just doesn't run properly. Its not running the
correct macro. Are there any weird rules about Strings in VB? Null
terminated? non null terminated? etc, etc.
 
Just a double quote at the beginning and end, nothing more required.

Double check that you didn't somehow overwrite the macro you think should be
running with the code from some other macro.

Of course, the UserIDs need to be in quotes as well.

And answering the question you had at the end, you only have two options for
startup:

- Have a macro named AutoExec
- Designate a start up form

You could have the AutoExec macro call the function, or you can have a
hidden form that calls the function in its Load event.
 
Yeah how do you start-up with a hidden form though? the form itself is
hidden, its set to load hidden, but startup loads it up visible.

-- I'd forgotten to put the id's in quotes, designating them as strings.
I'm surprised VB didn't ask me why i hadn't declared each of those userid's
as a variable name. It's been so long since i've really USED vb, i know it
lets you declare lots of things on the fly. I'm guessing it doesn't care
about variable declaration?
 
Using the form that opens on start-up with the OnLoad event:

DoCmd.OpenForm "Your Hidden Form", , , , , acHidden
 
Pwyd said:
-- I'd forgotten to put the id's in quotes, designating them as strings.
I'm surprised VB didn't ask me why i hadn't declared each of those
userid's
as a variable name. It's been so long since i've really USED vb, i know
it
lets you declare lots of things on the fly. I'm guessing it doesn't care
about variable declaration?

That indicates that you haven't told VBA to require that all variables be
declared. Without that, VBA assumed that the names were variables
(specifically, Variant variables initialized to a value of Null)

Go into the VB Editor and select Tools | Options from the menu. On the
Editor tab, ensure that the "Require Variable Declaration" is checked. That
will add a line "Option Explicit" to the top of all modules from now on.
Unfortunately, you'll have to go into all your existing modules and add that
line.
 
Back
Top