?
Solved

How can I set Startup Properties Using VBA?

Posted on 2009-04-20
23
Medium Priority
?
603 Views
Last Modified: 2013-11-28
Hello all,

I am trying to create an autoexec for my 2007 db by running an autoexec macro that will just run a module I've written pre-assigning all of the properties I need.  Basically I want the window to open with "frm_logon" displayed and the ONLY options available should be the windows button and then close database (I'm also working on dissabling all of the access/windows quick keys like 'ctl + n' and the like.  I'll attach what I've got so far....

I know I need a lot more, I just don't know what/how to do what I need, (I should add that that particular code doesn't DO anything right now either...)

thanks!
Public Sub NealTriesAutoexec()
 
Dim db As DAO.Database
 
Dim prop As DAO.Property
        
        Set db = CurrentDb()
        
        Set prop = db.CreateProperty("StartupForm", dbText, "Startup")
        
        db.Properties.Append prop
       
        db.Properties("AppTitle") = "Started at " & Now()
        
        db.Properties.Append prop
 
Application.RefreshTitleBar
 
End Sub

Open in new window

0
Comment
Question by:Sully143
  • 12
  • 9
  • 2
23 Comments
 
LVL 75
ID: 24190404
Open the vba editor.
Click the Help question mark ... then type in SetOption ... and pick SetOption Method - not the DAO method.

Then, click on Set Options From Visual Basic ... which will show you the complete list of options you can set using

Application.SetOption

mx
0
 

Author Comment

by:Sully143
ID: 24190474
So if I wanted to set my 'logon' to the startupform I would just say something like

Application.SetOption ("StartupForm", "frm_logon") ?  

I think I'm on the wrong track but I'm having syntax trouble as well as theory trouble
0
 
LVL 75
ID: 24190533
I don't see StartupForm in the list.  But, you can set the start up form in other ways.  In A2003 it's

Tools>>Startup>> Display Form/Page ... and pick your form.  And several other properties can be set here also.

Or in code, DoCmd.OpenForm "FormName"

mx

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Sully143
ID: 24190544
I need this to run from an autoexec macro that runs my 'startup' module when I open the db from the desktop.....
0
 
LVL 75
ID: 24191035
ok ... that's what I've been doing for years.

And ... besides other things, you can open your startup form in that procedure you are calling in the module ... with one line of code.

I'm not real clear on just what - overall - you are trying to do exactly ... what properties you are trying to set.

mx
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 24194106
in your autoexec macro, add this line in the Action column

openform




'fill in the the following at the lower part of the macro screen builder

Formname  < name of form>


0
 

Author Comment

by:Sully143
ID: 24197403
Capricorn,

I've been trying to do a lot of reading up on my own on startup properties and things like that lately and everywhere I look it says that setting the startup form via vba code that will run through a macro is the better way to do it.  Any thoughts?
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 24197588

if you already have an autoexec macro that performs certain functions when you start the db, then just add  the opening of your startup form as one of the actions in your autoexec macro.

opening startup form via vba code has the advantage of checking certain conditions are met (if there are any) before opening the form...

for me, it all depends on the designer, requirements of the db etc...
0
 

Author Comment

by:Sully143
ID: 24197616
ok well in this case, I suppose the form opening is pretty far down on the list of things that need to happen.  How about hiding everything in the MS ACCESS 2007 view BUT my forms, and maybe the windows button option to close db, how would I go about doing that?
0
 
LVL 75
ID: 24197637
Sully143:  You said

"I need this to run from an autoexec macro that runs my 'startup' module "

which I took to mean you want to open the startup form in code ?

mx
0
 

Author Comment

by:Sully143
ID: 24197682
Yes, I do want to set the startup form to my logon form in code.  
But reading what you and capricorn have said makes me think one just can't/shouldn't do it.  You have both told me to just use the openform macro function in my autoexec macro.  (instead of putting it into code that I just wanted the autoexec to run for me)
0
 
LVL 75
ID: 24197734
"what you and capricorn have said makes me think one just can't/shouldn't do it."

No. Where did I say that?

"You have both told me to just use the openform macro function in my autoexec macro."
I did not tell you this.

mx
0
 
LVL 75
ID: 24197752
There are at least 3 ways you can do this:

1) http:#a24190533

2) In the AutoExec macro as suggested above

3) In code ... which can be called by your AutoExec macro.

mx
0
 

Author Comment

by:Sully143
ID: 24197786
OK I get that.  I need to know HOW to do that.  That is why I pasted the little code I had before and asked HOW to make that work.  So going back to square one then, I want to do this in code that will be called by my auto exec.  How does one do that?
0
 
LVL 75
ID: 24197798
Add this line of code in your start up code:

DoCmd.OpenForm "YourStartupFormName"

mx
0
 
LVL 75
ID: 24197815
add the line of code at an appropriate point - after you have done what ever property setting and initializing you need to do.

mx
0
 

Author Comment

by:Sully143
ID: 24197831
should that code be a module?  or just a private sub somwhere (where?)?  And even then, I have trouble w/ the macro 'runcode' function b/c it asks for a function, and not a sub.  (this is where I am having my trouble.  I've had a lot of trouble setting the other startup properties here too)
0
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 2000 total points
ID: 24197888
It should be in a standard vba module.  You could call the Module


vbaStartup

Then, name your start up Function something different ... like.

mStartUp()

Public Function mStartUp()

'    your code

End Function

In you AutoExec macro, create an Action of RunCode ... and enter

=mStartUp()

in the action argument  ... including the equals sign.

mx
0
 

Author Comment

by:Sully143
ID: 24197992
What kind of code would I be writing to take away all of the ribbons, and things like that?  (Here I don't know syntax at all)

0
 
LVL 75
ID: 24198008
"should that code be a module? "
Yes ... a standard vba module (as opposed to in a Form module)

"or just a private sub somwhere (where?)?"
No.

"And even then, I have trouble w/ the macro 'runcode' function b/c it asks for a function, and not a sub."
Yes ... it must be a Function.  I *never* use Subs for anything ... there is no need in today's VBA and fast computers.

" I've had a lot of trouble setting the other startup properties here too)"
One step at a time.

If you still want to use / work with the code you posted (some of it) then

Public Sub NealTriesAutoexec()
>>
Public Function NealTriesAutoexec()    with corresponding End Function instead of End Sub.

mx
0
 
LVL 75
ID: 24198174
I don't use A2007 and the Ribbons are a big reason, so I can't help you there.  However, I do have several ribbon links.  Would you like me to post them?

mx
0
 

Author Comment

by:Sully143
ID: 24200906
actually yes, that would be great thanks
0
 
LVL 75
ID: 24201027
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Implementing simple internal controls in the Microsoft Access application.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question