Problem displaying a form that runs queries

Hello,
In Access 2007, I’m having a little issue displaying a form that runs 
queries on load.  Below is my code.
When I double click the form, the queries begin to run but the form only 
appears after the queries are done.
If I put the code behind a command button it works fine.   I can’t use a 
command button because I need the queries to run unattended when the DB 
opens.   Where am I going wrong?

Private Sub Form_Open(Cancel As Integer)
DoCmd.MoveSize 2880, 4320
End Sub


Private Sub Form_Load()
DoCmd.SetWarnings False
'**********************************
'QUERIES MUST BE RUN IN THIS ORDER
'**********************************
Me.lboActiveQuery.Caption = "Running 02_qtbl106SupplierProducts"
DoEvents
DoCmd.OpenQuery "02_qtbl106SupplierProducts_Delete"
DoCmd.OpenQuery "03_qtbl106SupplierProducts"

Me.lboActiveQuery.Caption = "Running 05_qtbl106SupplierInfo"
DoEvents
DoCmd.OpenQuery "04_qtbl106SupplierInfo_Delete"
DoCmd.OpenQuery "05_qtbl106SupplierInfo"

Me.lboActiveQuery.Caption = "Running 07_qSupplierProducts_InfoLink"
DoEvents
DoCmd.OpenQuery "06_qSupplierProducts_InfoLink_Delete"
DoCmd.OpenQuery "07_qSupplierProducts_InfoLink"

DoCmd.SetWarnings True
End Sub

0
Utf
3/9/2010 4:36:01 PM
access.formscoding 7493 articles. 0 followers. Follow

4 Replies
757 Views

Similar Articles

[PageSpeed] 21

h2fcell wrote:
>In Access 2007, I�m having a little issue displaying a form that runs 
>queries on load.  Below is my code.
>When I double click the form, the queries begin to run but the form only 
>appears after the queries are done.
>If I put the code behind a command button it works fine.   I can�t use a 
>command button because I need the queries to run unattended when the DB 
>opens.   Where am I going wrong?
>
>Private Sub Form_Open(Cancel As Integer)
>DoCmd.MoveSize 2880, 4320
>End Sub
>
>
>Private Sub Form_Load()
>DoCmd.SetWarnings False
>'**********************************
>'QUERIES MUST BE RUN IN THIS ORDER
>'**********************************
>Me.lboActiveQuery.Caption = "Running 02_qtbl106SupplierProducts"
>DoEvents
>DoCmd.OpenQuery "02_qtbl106SupplierProducts_Delete"
>DoCmd.OpenQuery "03_qtbl106SupplierProducts"
>
>Me.lboActiveQuery.Caption = "Running 05_qtbl106SupplierInfo"
>DoEvents
>DoCmd.OpenQuery "04_qtbl106SupplierInfo_Delete"
>DoCmd.OpenQuery "05_qtbl106SupplierInfo"
>
>Me.lboActiveQuery.Caption = "Running 07_qSupplierProducts_InfoLink"
>DoEvents
>DoCmd.OpenQuery "06_qSupplierProducts_InfoLink_Delete"
>DoCmd.OpenQuery "07_qSupplierProducts_InfoLink"
>
>DoCmd.SetWarnings True
>End Sub


There is no "After Load" event, but I think maybe you can
use a flag to let the Current event know when to run.  The
code would be along these lines:

module level variable section (at top of module, before any
procedures)
	Private bolLoadDone As Boolean

in load event
	bolLoadDone = True

in Current event
	If bolLoadDone Then
		'run the queries
		bolLoadDone = False
	End If

Note that, if those are all action queries, you should be
using the Execute method instead of OpenQuery.  (FYI
OpenQuery is for opening a Select query's datasheet, RunSQL
is for running action queries and Execute is almost always
preferred over RunSQL because it runs synchronously).

-- 
Marsh
MVP [MS Access]
0
Marshall
3/9/2010 6:37:11 PM
Suggest that you open a hidden form first.
Put the code that opens and runs the queries in a separate module and make 
it a public function.
The code to call the function tnat runs the queries would be in the hidden 
form.
When the queries have finished running, then open whatever form you want.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia


"h2fcell" <h2fcell@discussions.microsoft.com> wrote in message 
news:3E6F7025-0FF5-4B1C-BA10-2A853CAA8E4B@microsoft.com...
> Hello,
> In Access 2007, I'm having a little issue displaying a form that runs
> queries on load.  Below is my code.
> When I double click the form, the queries begin to run but the form only
> appears after the queries are done.
> If I put the code behind a command button it works fine.   I can't use a
> command button because I need the queries to run unattended when the DB
> opens.   Where am I going wrong?
>
> Private Sub Form_Open(Cancel As Integer)
> DoCmd.MoveSize 2880, 4320
> End Sub
>
>
> Private Sub Form_Load()
> DoCmd.SetWarnings False
> '**********************************
> 'QUERIES MUST BE RUN IN THIS ORDER
> '**********************************
> Me.lboActiveQuery.Caption = "Running 02_qtbl106SupplierProducts"
> DoEvents
> DoCmd.OpenQuery "02_qtbl106SupplierProducts_Delete"
> DoCmd.OpenQuery "03_qtbl106SupplierProducts"
>
> Me.lboActiveQuery.Caption = "Running 05_qtbl106SupplierInfo"
> DoEvents
> DoCmd.OpenQuery "04_qtbl106SupplierInfo_Delete"
> DoCmd.OpenQuery "05_qtbl106SupplierInfo"
>
> Me.lboActiveQuery.Caption = "Running 07_qSupplierProducts_InfoLink"
> DoEvents
> DoCmd.OpenQuery "06_qSupplierProducts_InfoLink_Delete"
> DoCmd.OpenQuery "07_qSupplierProducts_InfoLink"
>
> DoCmd.SetWarnings True
> End Sub
> 


0
Jeanette
3/9/2010 9:20:20 PM
The reason I want the form to appear is because as the queries run I change 
the Caption property of a Label on the form to display the name of the 
running query.  I’m not sure your suggestion will allow me to do that.  I’ll 
give it a try.
Thanks


"Jeanette Cunningham" wrote:

> Suggest that you open a hidden form first.
> Put the code that opens and runs the queries in a separate module and make 
> it a public function.
> The code to call the function tnat runs the queries would be in the hidden 
> form.
> When the queries have finished running, then open whatever form you want.
> 
> 
> Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
> 
> 
> "h2fcell" <h2fcell@discussions.microsoft.com> wrote in message 
> news:3E6F7025-0FF5-4B1C-BA10-2A853CAA8E4B@microsoft.com...
> > Hello,
> > In Access 2007, I'm having a little issue displaying a form that runs
> > queries on load.  Below is my code.
> > When I double click the form, the queries begin to run but the form only
> > appears after the queries are done.
> > If I put the code behind a command button it works fine.   I can't use a
> > command button because I need the queries to run unattended when the DB
> > opens.   Where am I going wrong?
> >
> > Private Sub Form_Open(Cancel As Integer)
> > DoCmd.MoveSize 2880, 4320
> > End Sub
> >
> >
> > Private Sub Form_Load()
> > DoCmd.SetWarnings False
> > '**********************************
> > 'QUERIES MUST BE RUN IN THIS ORDER
> > '**********************************
> > Me.lboActiveQuery.Caption = "Running 02_qtbl106SupplierProducts"
> > DoEvents
> > DoCmd.OpenQuery "02_qtbl106SupplierProducts_Delete"
> > DoCmd.OpenQuery "03_qtbl106SupplierProducts"
> >
> > Me.lboActiveQuery.Caption = "Running 05_qtbl106SupplierInfo"
> > DoEvents
> > DoCmd.OpenQuery "04_qtbl106SupplierInfo_Delete"
> > DoCmd.OpenQuery "05_qtbl106SupplierInfo"
> >
> > Me.lboActiveQuery.Caption = "Running 07_qSupplierProducts_InfoLink"
> > DoEvents
> > DoCmd.OpenQuery "06_qSupplierProducts_InfoLink_Delete"
> > DoCmd.OpenQuery "07_qSupplierProducts_InfoLink"
> >
> > DoCmd.SetWarnings True
> > End Sub
> > 
> 
> 
> .
> 
0
Utf
3/10/2010 2:26:01 PM
The reason that your form misbehaves is due to putting the code to run the 
queries with the load event.

A form will not display properly until it has finished its load event.
Your form runs all those queries in its load event - so it will not finish 
the load event until the queries have finished running.

Another suggestion (untested) is to use the current event instead of the 
load event.
The current event will fire after the load event is finished (usually) - you 
could test it.

Another alternative is to open the form normally - the one that shows the 
query that is running in a label. In addition have a hidden form that opens 
at the same time that calls the code that runs the queries.
You could use code on the hidden form to change the label on the visible 
form as each query is running.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia



"h2fcell" <h2fcell@discussions.microsoft.com> wrote in message 
news:46FD80C2-36A1-4FEB-8DD1-8C5D084AEEBC@microsoft.com...
> The reason I want the form to appear is because as the queries run I 
> change
> the Caption property of a Label on the form to display the name of the
> running query.  I'm not sure your suggestion will allow me to do that.  I'll
> give it a try.
> Thanks
>
>
> "Jeanette Cunningham" wrote:
>
>> Suggest that you open a hidden form first.
>> Put the code that opens and runs the queries in a separate module and 
>> make
>> it a public function.
>> The code to call the function tnat runs the queries would be in the 
>> hidden
>> form.
>> When the queries have finished running, then open whatever form you want.
>>
>>
>> Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
>>
>>
>> "h2fcell" <h2fcell@discussions.microsoft.com> wrote in message
>> news:3E6F7025-0FF5-4B1C-BA10-2A853CAA8E4B@microsoft.com...
>> > Hello,
>> > In Access 2007, I'm having a little issue displaying a form that runs
>> > queries on load.  Below is my code.
>> > When I double click the form, the queries begin to run but the form 
>> > only
>> > appears after the queries are done.
>> > If I put the code behind a command button it works fine.   I can't use 
>> > a
>> > command button because I need the queries to run unattended when the DB
>> > opens.   Where am I going wrong?
>> >
>> > Private Sub Form_Open(Cancel As Integer)
>> > DoCmd.MoveSize 2880, 4320
>> > End Sub
>> >
>> >
>> > Private Sub Form_Load()
>> > DoCmd.SetWarnings False
>> > '**********************************
>> > 'QUERIES MUST BE RUN IN THIS ORDER
>> > '**********************************
>> > Me.lboActiveQuery.Caption = "Running 02_qtbl106SupplierProducts"
>> > DoEvents
>> > DoCmd.OpenQuery "02_qtbl106SupplierProducts_Delete"
>> > DoCmd.OpenQuery "03_qtbl106SupplierProducts"
>> >
>> > Me.lboActiveQuery.Caption = "Running 05_qtbl106SupplierInfo"
>> > DoEvents
>> > DoCmd.OpenQuery "04_qtbl106SupplierInfo_Delete"
>> > DoCmd.OpenQuery "05_qtbl106SupplierInfo"
>> >
>> > Me.lboActiveQuery.Caption = "Running 07_qSupplierProducts_InfoLink"
>> > DoEvents
>> > DoCmd.OpenQuery "06_qSupplierProducts_InfoLink_Delete"
>> > DoCmd.OpenQuery "07_qSupplierProducts_InfoLink"
>> >
>> > DoCmd.SetWarnings True
>> > End Sub
>> >
>>
>>
>> .
>> 


0
Jeanette
3/11/2010 1:09:56 AM
Reply:

Similar Artilces:

Problem shortcuts in Word
Hello, I work with Word 2008. In the beginning there is no problem, but suddenly i have problem with shortcuts. When i want to do "cmd c" it make an other shortcuts same thing for "cmd s", "cmd v" and surly some other. But when i write there is no problem "c" is "c"... If somebody have an idea please help me. Thank you. Unless you indicate your specific update level of Office as well as OS X & describe what the keystrokes *are* doing contrary to what you expect there isn't much we can offer. -- Regards |:>)...

encoding problem in Outlook 2007 importing Outlook 2000 personal folders
I use Outlook 2007 to import the pst file of Outlook 2000. The Chinese characters in the subject became unreadable but it's ok to display in message body. In Outlook 2000, there's no problem to display the Chinese characters in the subject. What's wrong with Outlook 2007? What setttings should I change to fix the problem? Thanks. cyl <u8526505@gmail.com> wrote: > I use Outlook 2007 to import the pst file of Outlook 2000. The Chinese > characters in the subject became unreadable but it's ok to display in > message body. In Outlook 2000, there's no problem t...

I want to expose Action menu items as form buttons
I'm trying to expose Action menu items as form buttons by customizing the _recources/ISV.Config file. I'm trying to use the following code: <incident> <ToolBar ValidForCreate="0" ValidForUpdate="1"> <Button Title="Resolve Case" ToolTip="Resolve this case" Icon="/_imgs/ico_18_serviceReports.gif" Url="http://localhost/CS/cases/dlg_closecase.aspx" PassParams="1" WinParams="" WinMode="0"/> </ToolBar> </incident> It throws an error, so I can only assume that I'...

Outlook 2003 PST problems
I just installed Office 2003 professional on a new computer & am having problems with outlook. I copied my Outlook.pst file into the appropriate directory & although it is recognized the calendar is not working properly. I cannot attach any of the colored labels to my appointments - so everything is pretty much in black & white. I totally uninstalled & reinstalled office... first removing my pst file... but there appears to be an ini file... or something that is retaining some information... does anyone know of a fix for the labels... or how to TOTALLY uninstall office (so I...

Problem with Authentication
The CRM application was running smooth. But now I can't logging. It ask my credentials and than return a 401.1 error. I had already reinstalled the CRM server but it won't work. I'm accessing it in the same local network. I'm running CRM 3.0 in SBS. Best regards, Erico Hi When you open a Internet explorer and type the name of the CRM server, it prompts for user and password ? Are you logged in with domain credentials ( AD user ) ? If you are, so add url of the crm server in Local intranet. Enable "Automatic logon only in intranet", this is under security,c...

Vista blue screen problem...please help!
I've seen some other threads, here are the dump files: 'RapidShare: 1-CLICK Web hosting - Easy Filehosting' (http://rapidshare.com/files/347103149/Minidump.rar.html) Please, help me out here. -- ceVil It might be better to know at what point the bsod occurs and what the actual err.msg given is "ceVil" <guest@unknown-email.com> wrote in message news:0b9a0c60b90bf6c0be88bda30f2820ab@nntp-gateway.com... > > I've seen some other threads, here are the dump files: > 'RapidShare: 1-CLICK Web hosting - Easy Filehosting' > (...

calendar problem
Dear all, I am using both mail and calendar function in outlook 2002. Everything is ok until recently, when I try to make a new appointment or checking any old appointments, an error message "out of memory or resource, try to close some windows..." pop up. The mail function is still ok. Can anyone tell me how can I solve this? I have already installed sp2. The version of office is the professional one with frontpage. Thanks. tp ...

problem #4
Hi, I am facing this new problem... i.e a user has installed Office 2003 on win2k prof platform.. whenever she is working on a outlook.. she gets a Microsoft error message... saying to send the report or don't send the report... Usually I have seen this problem in IE... But for outlook it is new to me... after clicking on send or don't send report.. the outlook closes. And there are no IE open..... and if atall it is open.. the IE does not close... Need your help regards, KAH What is logged to the Event Viewer regarding this? Try one of the following already; http://www.howt...

95 and 97 problem
For some unknown reason there is Excel 95 and 97 on this pc.When i double click on an Excel file, the pc defaults to the 95 program (Which incidently doesn't work properly). So my question is how do i get the pc to default to 97. Cheers Craig Craig, Have a look at Windows Help. From Windows 2000 Help (Index under Programs Associating with File Types) To change which program starts when you open a file In My Computer or Windows Explorer, on the View menu, click Folder Options. Click the File Types tab. In the list of file types, click the one you want to change. Click Edit. In Act...

Date problem
I can't believe there's no post on this, but I can't find it. I've tried the solutions I could find (see below) and still get the error: "The expression is typed incorrectly or it is too complex to be evaluated. For example....Try simplifying...." I have a date field, formatted as Date/Time, General Date, default Value = Now(). I like having the date and the time - in case we need it. I want to run a report on calls taken just for one day. I have CallDate: CallDateAndTime in my query, with "criteria" as Between ([Forms]![frmReports]![txtStartDate]) A...

sync problems
I have all of my info on an HP Ipac. I had to reformat the hard drive and I did not make a back-up file. I am trying to move everything back to the computer but it says there is an error with syncing it. How can I move everything from the PDA back to Outlook again? Please help- thanks ...

Office 2007 - HELP
I have used Word for many years and love it - not too thrilled with the changes in Office 2007, but my bigger issue is with Publisher 2007. I have an image that I have used in Word just fine - meaning, the on screen colors are correct and when printed the colors are correct. Someone sent me a Publisher file and asked me to add the image - I did this - now the image is messed up - the colors are correct on screen, but when printed FROM MY computer the image colors are all wrong - but if I transport the file to a different computer it prints fine I have reinstalled Office - no good Any id...

Installation Problem!!
I am having a problem installing MSCRM 1.2. My configuration consists of a Domain Controller running Win 2000 Server SP4 . I am trying to install MSCRM on a member of the domain running Windows 2000 Server SP4. There is a DNS Server on the DC which is integrated with AD, and a SQL Server 2000 running on the Win 2K machine. The install errors out when CRM creates the root business with the message: Setup was unable to install Microsoft CRM Server. Setup was unable to provision your organization. Setup was unable to create the root business. The configuration of ASP.NET seems to be ok, the pr...

Problems Creating a disclaimer in Exchange 2003
I am trying to create a server based disclaimer that will stamp all of my smtp emails going to the internet. I have been following KB article 317680 with no luck. I get an error like the one below. Binding Display Name Specified: smtpscriptinghost ** Registration Failed ** Err.Number (HRESULT) = 0x1AD Err.Description = ActiveX component can't create object ProgID = cdo.ss_smtponarrival COM Category = {FF3CAA23-00B9-11d2-9DFB-00C04FA322BA} Corresponding Event = onarrival ** Have you registered your sink COM class on this machine? I am puttin...

Resource editor problems
Hello all, Under VC++ 7.1... Please consider these two lines: IDC_ARROW_ADD_CANCEL DISCARDABLE "res\\cur00004.cur" IDC_ARROW_ADD_CANCEL CURSOR DISCARDABLE "res\\cur00004.cur" The second is a hand-edited change to the first. Both will compile just fine in the resource compiler. However, after I use a text editor to make this change, I cannot open the .rc file in the resource editor. The resource editor issues the following error open attempting to open the .rc file: error RC2135 : file not found: CURSOR Can anyone shed light on what's going on here? Thanks, Dave ...

Directory Replication Problem #2
Hi, recently my Exchange Server directory database receives changes from other servers but does not send out its own changes. Check from the knowledge base, to correct the USN discrepancy need to use Authrest.exe (need to amke changes for about 100+ users). Does anybody know where to get this file 'Authrest.exe' for exchange server 5.5? Exchange server 5.5 CD only provide this file for ver.4.0. Have anyone use it before? Regards, "Sharon Tan" <sharon_tansk@yahoo.com.sg> wrote: >Hi, recently my Exchange Server directory database >receives changes from ot...

Cell Format
I have a spreadsheet with cells that I'm trying to type the date into. I type in the date exactly like this: 09/26/03. When I hit "enter" MS Excel displays "37890" in the cell. No matter what I do I can't the cell to show: 09/26/03. I think that somehow I need to "strip" the cell of what it's original format is, but I can't figure out how. I try to use the Date option in the format cell screen but it doesn't work. Curtis I tried this and it didn't work. I also tried the "Text to columns" feature. No success. >...

User Defined Variables in MS query cause a problem to import data
If I use user defined variables in MS query to import data into excel sheet, the query executes but no data gets imported into the excel sheet. If I get rid of the variable the results can be imported into the Excel sheet. ...

Hide dupes in a query
I have a query that lists all customers that have ordered from us since a certain date. SELECT tblContactData.ChurchName, tblAddresses.DCreated, tblAddresses.Address1, tblAddresses.City, tblAddresses.State, tblAddresses.Zip, tblOrderHdr.ShipAddressID, Max(tblOrderHdr.OrderDate) AS MaxOfOrderDate, tblContactData.ContactID FROM ((tblContactData INNER JOIN tblAddresses ON tblContactData.ContactID = tblAddresses.aContactId) INNER JOIN tblStatus ON tblContactData.ConStatusID = tblStatus.StatusID) INNER JOIN tblOrderHdr ON tblContactData.ContactID = tblOrderHdr.oContactID GROUP BY...

outlook web access redirect problem
hi, I have been trying to redirect outlook web access (OWA) from the IIS root folder to the /exchange folder. I have followed the instructions on going into the web site and redirecting to a folder but I just get the following URL when I browse to the root of my webserver : http://webmail/exchange/exchange - it's like it's doubling up somehow. I have it set to : A redirection to a URL redirect to: /exchange client will be sent to: A directory below URL entered I just can't work it out... any ideas... cheers Baronne Which instructions did you follow? I wrote the below articl...

Problem after sorting
In my Excel 2007 workbook I have two sheets The "Master Names" sheet has columns: (A) First|(B) Last (C) First (B) Last (concatenated) The "Selected Names" sheet contains (A) cells which link to selected (C) First Last (concatenated) cells in the Master Names sheet. Everything links and displays fine except when I add names to the bottom of the Master Names sheet and then sort using (B) Last name column. When I do this I get a 0 (zero) in the (A) First Second cells in the Selected names sheet and other cells in this sheet have the wrong name. Obviously I am doin...

IF AND problem
Need to isolate problems on 1600 rows Worksheet Row Dept Hrs. Dollars A5 120500 600 9000 A6 120600 400 8000 A7 130600 240 A8 130400 160 A9 140600 320 6400 A10 140200 100 2000 A11 140600 240 (Found out the dept has 2 leading blanks) Isolate problems on 0600 criteria pointing out when b has value and c = 0. OK if both are 0. A7 and A11 should stand out.. =IF((MID(A1,5,4)="0600")=AND(b1>=0=AND(c1>=0)),"NO","ok") Does this work for you: =IF(RIGHT(A...

unable to display check/radio box with transparent background
I am not able to get check boxes/radio buttons to be displayed with a transparent background in my dialogs. The general technique for displaying controls with transparent backgrounds is described in more than a few postings (e.g. http://groups.google.ca/group/microsoft.public.pocketpc.developer/browse_thread/thread/e5d77d8f30350f3a/22ea8e331b6cd993?lnk=st&q=dialog+bitmap+static+text+background+transparent#22ea8e331b6cd993 ). The general technique in MFC is as follows: HBRUSH CInsDialog:nCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { pDC->SetBkMode(TRANSPARENT); retur...

Only display fields if field matches criteria
I'm trying to build a query where the field only displays "Show" if the field matches a string. For example, I have about 20 fields and each of them has the check box to 'Show'. I only want the field to show if the text "Traffic =E2=86=94 PreCon" is in the field. I tried doing if statements and I found that if the first field doesn't match this criteria, then none of them show up. "Traffic =E2=86=94 PreCon" could be in field 3 or 13. I just want to filter through the fields and only show the ones that have that string. Any ideas? ...

One sheet running very slowly & file has expanded ++
Hi I hope you can help with this one... I have a spreadsheet with 7 sheets. After making a few fairly simple changes (to several sheets) I noticed that all operations on one particular sheet became very slow (e.g. editing a comment, floating toolbars 'crawl'over the screen, etc). I did the obvious stuff like re-booting the computer etc. Then I noticed that the file size had jumped from around 400k (previous saved version) to 5.6M! How do I got about finding and eliminating the problem on the sheet in question? Is the problem necessarily on the sheet that is running slow? The others ...