Are there functions/Or Events that are called automatically when the database file first opens and When it closes?

All,
I'm assuming its "Public Function init_something()" but I can't seem to find a reference to the correct syntax.  I'm using Access 2007.

Basically what I'm trying to do is initialize a list of global variables and I can't seem to figure out how to do it.

	Option Compare Database

	Public VariableName As String
	
	'Call Init - Will throw an error
	'VariableName = "Hello World" - Will throw an error

	Option Explicit

		Public Function Init()
	        	VariableName = "Hello World"
		End Function

		Private Sub btName_Click()
     			MsgBox (VariableName)
		End Sub

' this is the only way that I can seem to get this to work and I'm sure that there is a better way of doing it.

Private Sub test_Click()

     If VariableName = "" Then
         Call Init
     End If

     MsgBox (VariableName)
     VariableName = "Some New Value"
End Sub

Also are all modules initiated when the database first opens?
Is there an order to when they are loaded?

Thanks in advance. - CES
0
CES
3/21/2007 9:27:51 PM
access.formscoding 7493 articles. 0 followers. Follow

2 Replies
780 Views

Similar Articles

[PageSpeed] 26

All macros named AutoExec.


"CES" <none@none.com> wrote in message
news:uyNm$%23$aHHA.208@TK2MSFTNGP05.phx.gbl...
> All,
> I'm assuming its "Public Function init_something()" but I can't seem to
find a reference to the correct syntax.  I'm using Access 2007.
>
> Basically what I'm trying to do is initialize a list of global variables
and I can't seem to figure out how to do it.
>
> Option Compare Database
>
> Public VariableName As String
>
> 'Call Init - Will throw an error
> 'VariableName = "Hello World" - Will throw an error
>
> Option Explicit
>
> Public Function Init()
>         VariableName = "Hello World"
> End Function
>
> Private Sub btName_Click()
>      MsgBox (VariableName)
> End Sub
>
> ' this is the only way that I can seem to get this to work and I'm sure
that there is a better way of doing it.
>
> Private Sub test_Click()
>
>      If VariableName = "" Then
>          Call Init
>      End If
>
>      MsgBox (VariableName)
>      VariableName = "Some New Value"
> End Sub
>
> Also are all modules initiated when the database first opens?
> Is there an order to when they are loaded?
>
> Thanks in advance. - CES


0
Powderfinger
3/21/2007 11:03:54 PM
On Wed, 21 Mar 2007 17:27:51 -0400, CES <none@none.com> wrote:

>Also are all modules initiated when the database first opens?

No: only when a Sub or Function in the module is called. The modules just sit
there waiting to serve.

I'd suggest having a Form open automatically - use Tools... Startup and select
a form name. You can do your initialization code in that form's Open event.
Disable its Close button but provide a button to make it invisible so the user
doesn't inappropriately close and reopen it.

             John W. Vinson [MVP]
0
John
3/21/2007 11:18:53 PM
Reply:

Similar Artilces:

Single file won't print
I have an Excel worksheet that won't print. Others will as will Word and other app docs. When instructed to 'print' the messages are all there however, the file never gets to the printer even though the indications all says it does. I checked something somewhere but can't re-find it. Perhaps; "File->Print" -->"Print to File"(?) -- Regards; Rob ------------------------------------------------------------------------ "trob2002" <trob2002@discussions.microsoft.com> wrote in message news:AF7A9322-5451-46F0-AED7-81EF54B98F41@microsoft....

Save file with cell name
Hi In cell A1 i have =cell"filename"A1 giving me the I want to run macro that will save new file with data in A1 Example. tab named wc0701. new file saved as wc0701 Any idea's regards -- Message posted via OfficeKB.com http://www.officekb.com/Uwe/Forums.aspx/excel-new/200601/1 You could just drop the formula in A1 and use the worksheet name itself. with activesheet .parent.saveas filename:="C:\" & .name & ".xls", ...rest of options end with "Brian Thompson via OfficeKB.com" wrote: > > Hi > In cell A1 i have =cell"f...

If function using a list of criteria
i am using the If function, but i wish to expand the logical test criteria. I had three names that the cell could not equal, and previously did this by using three *AND(not = to)* instructions. Now however this has expanded to over a hundred names that i want the target to not equal. short of writing out 100 more AND commands in the if function how can i achieve this? The list of names i want to exclude are in the same excel file - could i perhaps link the if function to the table? any help greatly appreciated thanks Hi Use VLOOKUP for this. See http://www.contextures.com/xlFunctions02....

No In List Event
I am having trouble adding a record to the list. The list source is a is query called "qryCountries" on a ComboBox control. The coding is: Private Sub Country_NotInList(NewData As String, Response As Integer) Dim ctl As Control ' Return Control object that points to combo box. Set ctl = Me!Country ' Prompt user to verify they wish to add new value. If MsgBox("Value is not in list. Add it?", _ vbYesNo) = vbYes Then ' Set Response argument to indicate that data ' is being added. Response = ...

Seeing Two instances of the Data File in the TRee!
I am sorry for the obscure Subject line, but I can't think of a way to describe this. I am using Outlook with regular Internet Email. I have it set up with the standard one Data File. When I go to the Data Files page, there is only one file in use. But.. In the Tree on the Left (in Office 2003) I see 2 personal Folders (of the Data File) and they are exactly the same thing, when I get new email, both inboxes receive the file. Also, when I go to the Email Accounts page, and I want to choose which Data File to direct the emails to, it shows 2 options, both having the same name (Duh, ...

file locations #2
I would like to know in what folder I can find my saved e- mail messages so I can save them to a back-up disk "Don" <anonymous@discussions.microsoft.com> wrote in message news:044701c3db05$1bbe6d90$a501280a@phx.gbl... > I would like to know in what folder I can find my saved e- > mail messages so I can save them to a back-up disk What OS and what version of Outlook? ...

Automatically create trend table using symbols
Good evening, A client wants to create a table of data for a PowerPoint presentation, where tolerance to budget is indicated by a symbol: one symbol for <5% variance to budget; a second symbol for 6-10% variance to budget, and a third symbol for >10% variance to budget. Of course, it could be done manually but he wants to automatically insert a symbol for each of the three ranges. Is there an easy way to do this? thanks, Christine -- cmbl ------------------------------------------------------------------------ cmbl's Profile: http://www.excelforum.com/member.php?action=geti...

How do I tie a web form to an excel database #2
I have created a webpage form in word. I would like to supply the data input into the form to an excel database auomatically. Can anyone give me an example or supply me with directions? Thanks ...

Workflow Process for Opportunities Open past Est Close Date
I have been trying to create a Workflow Process that checks the Opportunity Close Date and sends an email out to the User (or User Manager) when the Opportunities are past the due date. Can anyone tell me if this is possible? The problem is recognizing when it is past due. Thank you ahead of time. ...

XML file width
I'm converting a 1MB bitmap file into base64 encoding..and saving into an xml file. the xml file and everything works perfectly...except when i open the xml file in a viewer I get errors becuase the file is written to just one line with no coluumn width etc? how can I ensure the xml writer in vb.net spits out beautifully formatted xml code like the access 2003 etc..?? with my 1MB <image> tag spread over thousands of lines 80 chars wide instead of just 1 long line that crashes any text editor...? cheers Simon Simon wrote: > I'm converting a 1MB bitmap file into b...

Automatic data collection in Manufacturing
How does this work? I see where you can designate a workstation as an ADC processor, but where do you setup to let your bar code scanner enter information. What exactly is the setup on this? Anyone? "Dnelson" wrote: > How does this work? I see where you can designate a workstation as an ADC > processor, but where do you setup to let your bar code scanner enter > information. What exactly is the setup on this? If you figure the answer, do post. I will be interested in knowing this too. Scott "Dnelson" wrote: > How does this work? I see where you ca...

Report problem with ODBC Call Failed
Good Day! I have a form that has two date fields that are date/time pickers, a combo box and a button. i also have a query that uses serveral tables from an odbc from a pervasive DB. That query is bound to several reports. keep in mind they all use the same query. now on that form, the user chooses the date frame of the query, (the query criteria is bound to these date/time pickers), and then chooses an option from the combo box, then then clicks the button. when the button is clicked, there is a 'select' that is based on the option selected from the combo box, and then opens th...

Excel says file is reserved
I have an Excel file shared by various people and it will not open completely because it says the file is reserved by one of our members. That person doe not have the file open and it won't even let him open the file. We have tried rebooting all the computers that use the file, but that didn't work. How do I get the reserve off of this file? Clear out the Temp directories on the computer that Excel says it is reserved for. c:\windows\temp and c:\Documents & settings\<user name>\Local settings\Temp (will need to set windows to show hidden and system files) Reboot &q...

denial of access to sent pdf files
I don't know if this is the correct forum. I have Outlook Express. Why can't I access a pdf document sent to me when I have Acrobat Reader installed? The message suggests that each pdf attachment I receive is "unsafe." What's going on? Tools, Options, SEcurity. Uncheck the box marked "don't allow attachments..." -- Patricia Cardoza Outlook MVP www.cardozasolutions.com Author, Special Edition Using Microsoft Outlook 2003 ***Please post all replies to the newsgroups*** "Lee Calem" <anonymous@discussions.microsoft.com> wrote in mess...

Problem enumurating file from FAT & NTFS disks.
Hello I have a problem using "CFileFind". This is behaving in differently on FAT and NTSF drives. - When tried to enumurate files from a directory on FAT disk, its getting the file in the order they have been created. - When tried to enumurate files from a directory on NTFS disk, its getting in the Alphabetical order. My requirement is to enumurate the files in order they have been created on both FAT and NTFS. Could any one suggest me a solution. regards "Vinay Ch" <vinaychima0@lycos.com> wrote: >Hello > I have a problem using "CFileF...

Publisher 2003 files lose Graphics when saved to 2000
I used Publisher 2002 to produce files for Publisher 2000 users which has worked fine. However, when I save files as 2000 made with Publisher 2003, then open with 2000, I get graphic place holders with no graphics. What am I doing wrong? Thanks! Publisher 2000 did not use compression for images. PUB2000: File Size Increases Unexpectedly When You Insert Picture http://support.microsoft.com/default.aspx?scid=kb;en-us;253973 How to troubleshoot a damaged publication in Publisher 2000 http://support.microsoft.com/default.aspx?scid=kb;en-us;198256 -- Mary Sauer MS MVP http://office.micros...

Cannot attach files to out going e-mail in Outlook 2000
When I attempt to attach my resume' to outgoing e-mail in Outlook I recieve the following message "Can't create file:XXXX.XXX Right-click the folder you want to create the file in, and then click Properties on the shortcut menu to check your permissions for the folder." I'm running windows 2000 and I have made sure that all file permissions are set properly. Any ideas would be helpful. CRPolk ...

Cannot convert Money 98 Files to 2004 nor 2001 Demo version
I installed a demo version of MS Money 2004 to see if it is worth upgrading from Money 98. I tried to open my .MNY file and had the error : "Money cannot open this file because it was created by an incompatible version.". I tried everything said in the Microsoft support article Q304254. But still was not able to do it. I even tried with a demo version of MS Money 2001. Please help. Thank you When you upgrade you must stay within a region i.e. US to US or UK to UK. It is likely that your M98 is non US and you have downloaded the US trial. What region is your M98? -- Regard...

Outlook exchange server kepping files on server
How do I set up an outlook xp client to exchange server so that mail is not automatically removed from the server? I would like to still have access through web access but currnently find that when i use outlook it takes the files off the server making the web mail in box always empty. Sounds like you're using a PST file to get your Exchange mail as opposed to using your mailbox and offline folders (OST file). You might want to check with your admin about setting you up with offline folders "peter" <anonymous@discussions.microsoft.com> wrote in message news:219f01c3e0...

Cannot open folders: Entourage cannot open the item due to an error
Version: 2008 Operating System: Mac OS X 10.6 (Snow Leopard) Processor: Intel Email Client: pop When I try and open one of my subfolders, either in Inbox or Folders on My Computer, I get an error message: Entourage cannot open the item due to an error. An unknown error has occurred in Entourage. And the folder doesn't open. <br><br>This is very bad for me as these are work folders that I need to access often. Not all of them are doing this, but more and more are doing this each day. Admittedly, i have about 200 subfolders and about 20 of them don't open. Is this ...

Close Excel Completely Using VBA #2
Damn.......It does ask me if I want to save the changes. Can this be stopped by adding another code after the Application.Quit Hpoe you can help! Celtic_Avenge -- Celtic_Avenge ----------------------------------------------------------------------- Celtic_Avenger's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=1410 View this thread: http://www.excelforum.com/showthread.php?threadid=27391 Hmm, it is working for me. Make sure you make a call to Save right before this call. Also make sure you save any other workbooks that might be open. Also make sure if ...

Cannot open pdf file attachement
When I installed the Acrobat 6, I was asked to removed version 5. But after installing Acrobat 6, I could not open all pdf file attachment. This is the error message: The system cannot find the path specified" I must have removed a registry when I uninstalled aAdobe version 6. Can anyone help to resolve the problem? Best regards, Steven A ...

Can i import a WAB file into Outlook 97 ?
How can I import a 'wab' address file into Outlook 97? -- Gerry Mitas Ryemont Abbey, Leixlip, Co. Kildare Phone: 01 6104509 Fax:01 601 4716 Info@mitas.ie www.mitas.ie _______________ DISCLAIMER: This e-mail may contain proprietary information, and is covered by copyright. It may be legally privileged, and is for the intended recipient only. If you are not the intended recipient you must not use, disclose, distribute, copy, print or rely on this e-mail. You'd have to import it into Outlook Express on that same machine first, then use Outlook Express's File | Export com...

TextBox Bound to Memo Filed displays the first 255 Chr
hi everyone I have a "Notes" field which is set on the table as a MEMO field. The notes field is loaded into a form (bound) .the "Notes" field contains more than 255 characters. However, the "Notes" field (which is already a memo field type bound to textbox) the textbox cuts off all data after 255 characters. please help thanks Wael If the form is based directly on the table (not on a query), you probably have something in the Format property of the text box on the form, or in the Format property of the field in the table. Eliminate whatever is in the ...

Order by on form open
Private Sub DateOfServiceLabel_Click() If Right(Me.OrderBy, 4) = "DESC" Then Me.OrderBy = "[DateOfService]" Else Me.OrderBy = "[DateOfService]" & " DESC" End If Me.OrderByOn = True Me.OrderByOn = True ------------------------------------------------------------- Private Sub DoctorLabel_Click() If Right(Me.OrderBy, 4) = "DESC" Then Me.OrderBy = "[Doctor]" Else Me.OrderBy = "[Doctor]" & " DESC" End If Me.OrderByOn = True Me.OrderByOn = True I use these codes on the on click event of the label...