Auto Open Procedures In Access !

Jaafar Tribak

Well-known Member
Joined
Dec 5, 2002
Messages
9,729
Office Version
  1. 2016
Platform
  1. Windows
Hi all,

I would like to run a procedure upon opening a DB file ( Not a DB object). Something like the Workbook_Open procedures in an Excel workbook.How do I do that ?

Regards.
 
tails said:
well with the database name, what is the name of the application... not the database itself, but the application name, eg. when you saved it what did u call it when you first open access to create it.

No tails. That will not work as the name of the DB is not a member of the DB application object.

Regards.
 
Upvote 0

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
OK good news. I think I found something interesting.

After some Google search I have adpted some code that makes use of the apiShowWindow API function.

Below are the steps I followed:

1-In the AutoExec macro I have : OpenForm ==> FrmWelcome
2-In a Standard Module I have the following code:

Code:
Option Compare Database

Global Const SW_HIDE = 0

Private Declare Function apiShowWindow Lib "user32" _
Alias "ShowWindow" (ByVal hwnd As Long, _
ByVal nCmdShow As Long) As Long

Public Function fSetAccessWindow(nCmdShow As Long)
    Dim loX  As Long
    loX = apiShowWindow(Application.hWndAccessApp, nCmdShow)
End Function

3- In the Form events Module I have the code below:

Code:
Private Sub Form_Load()
 fSetAccessWindow (SW_HIDE)
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Application.Quit
End Sub


That's it you can now open the DB file & have the Welcome form you want displayed without the Access window or Menus getting in your way making your DB program look much more neat & professionnal.

Note that ,for this to work,you have to make the Form Modal via the Form's properties window !

Regards.
 
Upvote 0
Hi Jaafar
That is a pretty neat function. I found that if you set the form property 'Pop Up' to No then it doesn't work (Access disappears but the form won't display) but if you set it to Yes it works, but prevents me from opening other screens and previewing reports from my 'Main Menu form' - do you have the same effect or is there another setting to change?
Andrew :)
 
Upvote 0
andrew93 said:
Hi Jaafar
That is a pretty neat function. I found that if you set the form property 'Pop Up' to No then it doesn't work (Access disappears but the form won't display) but if you set it to Yes it works, but prevents me from opening other screens and previewing reports from my 'Main Menu form' - do you have the same effect or is there another setting to change?
Andrew :)

Yes Andrew, I have the same effect. I have tried toggling the PopUp & Modal properties dynamically but no luck so far.

Hope someone can solve this.

Regards.
 
Upvote 0
As a further point make sure that you have adequate error handling. If you hide the application window and experience certain errors, it will appear that access is no longer running, when in fact it is.

This could cause issues for your users and data corruption if users try to re-open the database.

Just something to think about.
 
Upvote 0
hi,

some good stuff about this here and here

error handling very important or you'll get moaned at & ruin a User's day (a bonus if they are like Jenny23 ?!)

stubby
 
Upvote 0

Forum statistics

Threads
1,221,875
Messages
6,162,563
Members
451,775
Latest member
Aiden Jenner

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top