Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / May 2008

Tip: Looking for answers? Try searching our database.

quick code question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Pwyd - 30 May 2008 16:30 GMT
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?
PJFry - 30 May 2008 17:09 GMT
Remove the parens and enclose the macro name in quotes.

Write back if that does not work.

PJ

> Public Function AdminCheck()
>
[quoted text clipped - 19 lines]
> database Startup menu option, or do i need to make a hidden form that loads
> the function in a macro?
Pwyd - 30 May 2008 18:40 GMT
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.

> Remove the parens and enclose the macro name in quotes.
>
[quoted text clipped - 25 lines]
> > database Startup menu option, or do i need to make a hidden form that loads
> > the function in a macro?
Douglas J. Steele - 30 May 2008 18:59 GMT
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.

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

> 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
[quoted text clipped - 30 lines]
>> > loads
>> > the function in a macro?
Pwyd - 30 May 2008 19:35 GMT
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?

> Just a double quote at the beginning and end, nothing more required.
>
[quoted text clipped - 46 lines]
> >> > loads
> >> > the function in a macro?
PJFry - 30 May 2008 20:51 GMT
Using the form that opens on start-up with the OnLoad event:

DoCmd.OpenForm "Your Hidden Form", , , , , acHidden

> 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.  
[quoted text clipped - 55 lines]
> > >> > loads
> > >> > the function in a macro?
Douglas J. Steele - 30 May 2008 21:09 GMT
> -- 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
[quoted text clipped - 3 lines]
> 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.

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.