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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Startup procedure 1

Status
Not open for further replies.

Zeroanarchy

Technical User
Jun 11, 2001
630
AU
Ok created the following code to run on start up so as it makes all the menus + extra disapear, only problem is I do not know where to put it. lol If I put it in with the startup form none of it will work. Tried making an Autoexec module but of course that is not called on at start up. Can anyone advise me as to where you place code that you want to run before your first form appears. Set by set might help.
Thanks ZeroAnarchy

Private Sub Autoexec()
Dim db As Database
Dim prp As Property
Dim intX As Integer
Set db = CurrentDb

Application.SetOption "Show Hidden Objects", False
Application.SetOption "Show System Objects", False
Application.SetOption "Provide Feedback With Sound", False
Application.SetOption "Show Values Limit", 10000
Application.SetOption "Move After Enter", 1
Application.SetOption "Behavior Entering Field", 0
Application.SetOption "Arrow Key Behavior", 1
Application.SetOption "Show Status Bar", False
Application.SetOption "Default find/replace behavior", 1
DoCmd.OpenForm "Data"
DoCmd.ShowToolbar "Database", acToolbarNo
DoCmd.ShowToolbar "Filter/Sort", acToolbarNo
DoCmd.ShowToolbar "Form Design", acToolbarNo
DoCmd.ShowToolbar "Form View", acToolbarNo
DoCmd.ShowToolbar "Formatting (Datasheet)", acToolbarNo
DoCmd.ShowToolbar "Formatting (Form/Report)", acToolbarNo
DoCmd.ShowToolbar "Macro Design", acToolbarNo
DoCmd.ShowToolbar "Menu Bar", acToolbarNo
DoCmd.ShowToolbar "Print Preview", acToolbarNo
DoCmd.ShowToolbar "Query Datasheet", acToolbarNo
DoCmd.ShowToolbar "Query Design", acToolbarNo
DoCmd.ShowToolbar "Relationship", acToolbarNo
DoCmd.ShowToolbar "Report Design", acToolbarNo
DoCmd.ShowToolbar "Source Code Control", acToolbarNo
DoCmd.ShowToolbar "Table Datasheet", acToolbarNo
DoCmd.ShowToolbar "Table Design", acToolbarNo
DoCmd.ShowToolbar "Toolbox", acToolbarNo
DoCmd.ShowToolbar "Utility 1", acToolbarNo
DoCmd.ShowToolbar "Utility 2", acToolbarNo
DoCmd.ShowToolbar "Web", acToolbarNo
DoCmd.ShowToolbar "Visual Basic", acToolbarNo
Set prp=db.CreateProperty("AllowByPassKey",dbBoolean, False)
Set prp=db.CreateProperty("StartupShowDBWindow",DB_BOOLEAN, False)
Set prp=db.CreateProperty("StartupShowStatusBar", DB_BOOLEAN, False)
Set prp = db.CreateProperty("AllowBuiltinToolbars", DB_BOOLEAN, False)
Set prp = db.CreateProperty("AllowFullMenus", DB_BOOLEAN, False)
Set prp = db.CreateProperty("AllowBreakIntoCode", DB_BOOLEAN, False)
Set prp = db.CreateProperty("AllowSpecialKeys", DB_BOOLEAN, False)

End Sub
 
Can you not call the module from an autoexec macro? Robbo ;-)
 
I have tried adding a Autoexec module and using the open module option, all it does is just that opens it it does not run it.
 
In the On Load event of your main form, put this code:

Private Sub Form_Load()
'Do stuff
End Sub Nate Gagne
nathan.gagne@verizon.net

Like my post? Let me know it was helpful!
 
Zeroanarchy, I think you've misunderstood me.

Create a new macro named autoexec.

Set the first action to 'RunCode', enter the name of your function in the 'function name' box. (I'd suggest changing it from autoexec() to avoid confusion).

As far as I'm aware the autoexec macro runs before any objects like forms etc load so it should work! Robbo ;-)
 
ngagne.

If I am correct the main form you are refering to is the first form that I have loading in my autoexec if this is the case I have tried that and the problem is alot of the procedures I am trying to run need to tAke effect before the first form loads up. Also if it loads on the first form the global menu stays and I can not get rid of it. The global menu is the main one I am trying to get rid of. Also I am trying to take down the Access background form and only have my form floatin on the screen. Use to have a procedure that did it but I seem to have forgot how to do it.
 
Hi!

Robbo is right about using the RunCode command instead of the OpenModule, but you will need to change the Private Sub to Public Function.

hth Jeff Bridgham
bridgham@purdue.edu
 
robbo,

would like to try it your way but becomming a little stuck here is where I am at

Macro: Autoexec
First action: RunCode
Function Name: Data()

Ok as you recommended I have changed the module from Autoexec to data

and the Function as follows: Private Function data()

Problem error does not reconize argument.

thanks Zero

 
Is data a reserved word? Try calling your function something like StartRoutine() or something.

Also make sure that you have changed the 'end sub' bit to 'end function'.

You can see a list of available functions by clicking the build button, double clicking the 'functions' folder and you get two options: 'Built in functions' and '<Your db Name>. Double click that and you'll get the list.

A final thought - have you saved the module changes? I've forgotten to do that before and ended up chasing round for ages! Robbo ;-)
 
ok changed: Private Function data()
to : Public Function Data()

I am still having no luck, believe the problem is to do with Function name in the autoexec macro
currently set to:Data()

thanks so far hope you can help me with this last little bit

Zero
 
Hmmm, try using the expression builder from the 'function name' box. Does the name of your function appear? Robbo ;-)
 
tried the expression builder and found data() selected and ran the macro

the error I am getting on running the macro is as follows:
the expression you entered has a function name that project carnt' find.

Macro Name: Autoexec
Condition: True
Action name: run code
Arguments: Data()

thanks Zero
 
renamed the module to startroutine as well as the procedure it to startroutine: Public Function startroutine()

tried the expression builder and found startroutine() selected and ran the macro

the error I am getting on running the macro is as follows:
the expression you entered has a function name that project carnt' find.

Macro Name: Autoexec
Condition: True
Action name: run code
Arguments: startroutine()

thanks Zero
 
Robbo thankyou very much for your help, after playing for some considerable amount of time, i aventualy worked out that the module and the function should not have the same name. Amaxing one small thing can make life hard. So thanks again for your help.

Zero :)
 
It sounds like you got this problem figured out...but next time, you will run into fewer naming convention issues if you use a prefix that describes the object. For example, you could have called your query &quot;qryData&quot; and you could have called your module &quot;modData&quot; then you could have named them the same (but different).
 
hi,

continuing the theme of this problem, i get a compile error, after following the above

it doesn;t seem to like the declaration (s)
i.e. Dim db As Database
i get compile error : User-defined type not defined

please help!
-Martin
 
Hi Martin!

You need to go into a code window and choose Tool/References. Then you will to check mark the DAO 3.51 or 3.6 Object Library. Finally, move the library up, using the arrow keys, until it is above the reference to the ADO Object Library. Alternatively, instead of moving the reference up, you can do an explicit declaration such as:

Dim dbs As DAO.Database

hth Jeff Bridgham
bridgham@purdue.edu
 
blurworld try this.


Public Function start()
Dim intX As Integer
Dim db As Database
Dim prp As Property
Set db = CurrentDb
Application.SetOption &quot;Show Startup Dialog Box&quot;, False
Application.SetOption &quot;Form Template&quot;, False
Application.SetOption &quot;Show Hidden Objects&quot;, False
Application.SetOption &quot;Show System Objects&quot;, False
Application.SetOption &quot;Provide Feedback With Sound&quot;, False
Application.SetOption &quot;Show Values Limit&quot;, 10000
Application.SetOption &quot;Move After Enter&quot;, 1
Application.SetOption &quot;Behavior Entering Field&quot;, 0
Application.SetOption &quot;Arrow Key Behavior&quot;, 1
Application.SetOption &quot;Show Status Bar&quot;, False
Application.SetOption &quot;Default find/replace behavior&quot;, 1
DoCmd.ShowToolbar &quot;Database&quot;, acToolbarNo
DoCmd.ShowToolbar &quot;Filter/Sort&quot;, acToolbarNo
DoCmd.ShowToolbar &quot;Form Design&quot;, acToolbarNo
DoCmd.ShowToolbar &quot;Form View&quot;, acToolbarNo
DoCmd.ShowToolbar &quot;Formatting (Datasheet)&quot;, acToolbarNo
DoCmd.ShowToolbar &quot;Formatting (Form/Report)&quot;, acToolbarNo
DoCmd.ShowToolbar &quot;Macro Design&quot;, acToolbarNo
DoCmd.ShowToolbar &quot;Menu Bar&quot;, acToolbarNo
DoCmd.ShowToolbar &quot;Print Preview&quot;, acToolbarNo
DoCmd.ShowToolbar &quot;Query Datasheet&quot;, acToolbarNo
DoCmd.ShowToolbar &quot;Query Design&quot;, acToolbarNo
DoCmd.ShowToolbar &quot;Relationship&quot;, acToolbarNo
DoCmd.ShowToolbar &quot;Report Design&quot;, acToolbarNo
DoCmd.ShowToolbar &quot;Source Code Control&quot;, acToolbarNo
DoCmd.ShowToolbar &quot;Table Datasheet&quot;, acToolbarNo
DoCmd.ShowToolbar &quot;Table Design&quot;, acToolbarNo
DoCmd.ShowToolbar &quot;Toolbox&quot;, acToolbarNo
DoCmd.ShowToolbar &quot;Utility 1&quot;, acToolbarNo
DoCmd.ShowToolbar &quot;Utility 2&quot;, acToolbarNo
DoCmd.ShowToolbar &quot;Web&quot;, acToolbarNo
DoCmd.ShowToolbar &quot;Visual Basic&quot;, acToolbarNo
DoCmd.OpenForm &quot;data&quot;
ChangeProperty &quot;StartupForm&quot;, dbText, &quot;Data&quot;
ChangeProperty &quot;StartupShowDBWindow&quot;, dbBoolean, False
ChangeProperty &quot;StartupShowStatusBar&quot;, dbBoolean, False
ChangeProperty &quot;AllowBuiltinToolbars&quot;, dbBoolean, False
ChangeProperty &quot;AllowFullMenus&quot;, dbBoolean, False
ChangeProperty &quot;AllowBreakIntoCode&quot;, dbBoolean, False
ChangeProperty &quot;AllowSpecialKeys&quot;, dbBoolean, False
ChangeProperty &quot;AllowBypassKey&quot;, dbBoolean, True
intX = AddAppProperty(&quot;AppTitle&quot;, dbText, &quot;my program &quot;)
intX = AddAppProperty(&quot;AppIcon&quot;, dbText, &quot;C:\Program Files\my.ico&quot;)
RefreshTitleBar
End Function
----------------------------------------------------
Function ChangeProperty(strPropName As String, varPropType As Variant, varPropValue As Variant) As Integer
Dim dbs As Database, prp As Property
Const conPropNotFoundError = 3270

Set dbs = CurrentDb
On Error GoTo Change_Err
dbs.Properties(strPropName) = varPropValue
ChangeProperty = True

Change_Bye:
Exit Function

Change_Err:
If Err = conPropNotFoundError Then ' Property not found.
Set prp = dbs.CreateProperty(strPropName)

Resume Next
Else
' Unknown error.
ChangeProperty = False
Resume Change_Bye
End If
End Function
--------------------------------------------------------
Function AddAppProperty(strName As String, varType As Variant, varValue As Variant) As Integer
Dim dbs As Database, prp As Property
Const conPropNotFoundError = 3270

Set dbs = CurrentDb
On Error GoTo AddProp_Err
dbs.Properties(strName) = varValue

AddAppProperty = True

AddProp_Bye:
Exit Function

AddProp_Err:
If Err = conPropNotFoundError Then
Set prp = dbs.CreateProperty(strName, varType, varValue)
dbs.Properties.Append prp
Resume
Else
AddAppProperty = False
Resume AddProp_Bye
End If
End Function


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top