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

Open Database 1 off event

Status
Not open for further replies.

Binnit

Technical User
Apr 28, 2004
627
US
I would like to run a Dcount statement only when the database is first opened.

I have currently put this in to the main switchboard but of course it triggers the Dcount each time the switchboard is opened.

I presume there are be a number of ways to do this but I'm not sure what would be the normal method.

Any ideas?


If IT ain’t working Binnit and Reboot
 
How about an autoexec macro or the /x start-up switch?
 
Remou
Thanks

I could use an Autoexec macro, however, I'm not familier with macro constructs as I normally just use vb modules.

Which "Action" would you use to fire up the Dcount statement followed by a msgbox?





If IT ain’t working Binnit and Reboot
 
By the way, what is a /X start-up switch?

If IT ain’t working Binnit and Reboot
 
Use the macro to run a function. The /X switch is a similar idea.

/x macro
Starts Microsoft Access and runs the specified macro. Another way to run a macro when you open a database is to use an AutoExec macro.
- Microsoft Help
 
In detail..
create a module and paste the code (change appropriate)below
Code:
Public Function CountNumber()
    Dim i As Integer
    i = DCount("*", "table1")
    MsgBox "Count of Record(s) = " & i
End Function
Save and close

Create a macro
Action = RunCode
Function Name= CountNumber()

Save as "AutoExec" and close db
reopen the db and test.

________________________________________________________
Zameer Abdulla
Help to find Missing people
Sharp acids corrode their own containers.
 
ZmrAbdulla
Thanks for the example I can now put this in to an Autoexec action.

Remou
I am really curious about the alternative /x, are you able to elaborate a little further how this is called/used to start Access?

Thanks to both


Happiness is...not getting what you want but wanting what you have already got
 
Create a macro using, say, Msgbox to say Hello and save it as Hello, then create a shortcut to your database like so:
[tt]"C:\Program Files\Microsoft Office\Office\MSAccess.exe" "C:\Docs\Tek-Tips.mdb" /x Hello[/tt]

A third option is to use a startup form (Tools->Startup)which runs any once-off code and then opens the switchboard.
 
Remou
OK thanks for that clarification, will check it out.

Happiness is...not getting what you want but wanting what you have already got
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top