Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Developer Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
MainMenuForm Problem
Ronald de Boer 
      
2 years ago
Hi,
I have created a form which is the Form setup in Options (Display Form) which retrieves the Windows environment variable USERNAME. This Forms record source is a Query which uses USERNAME as criteria and I store this in TempVars("UserID") in the OnLoad event.  I display  TempVars("UserID") on the Form and it is retrieved and displayed on the form correctly.

My problem is the Query the Form is based on does not have any records in it until the query has been run and the query hasn't been run because the form is loaded when the application starts.

I have tried to do a Docmd.OpenQuery in the events Onload and OnOpen but nothing works.

When I close the form run the query manually so the TempVars("UserID") is still in memory and then run the form again the forms displays the records as expected.

How do I run this query after I have retrieved and populated TempVars("UserID") when this form is the first form loaded when the application runs.

DetailsPrivate Sub Form_Load()

    Dim objNetwork As Object
    Dim userName As String
    
    ' Create a WScript.Network object
    Set objNetwork = CreateObject("WScript.Network")
    
    ' Retrieve the username
    userName = objNetwork.userName
    TempVars("UserID") = userName
    ' Clean up
    Set objNetwork = Nothing
    DoCmd.OpenQuery "ApplicationQ"
    
End Sub


DetailsPrivate Sub Form_Open(Cancel As Integer)

    DoCmd.OpenQuery "ApplicationQ"

End Sub


DetailsPrivate Sub QuitBtn_Click()

    DoCmd.Quit
    
End Sub


Regards and Thx
Ron de Boer
Matt Hall  @Reply  
          
2 years ago
You might check out Open Date Picker on Load.
Gary James  @Reply  
      
2 years ago
You can also use the forms TimerInterval property in milliseconds to have the form delay an action till sometime later.   Simply hook into the Timer Event to handle the delay, then set the interval property to zero to stop the timer from firing the event any further.   This example shows how the timer can be used to make an icon flash between two different images.

https://learn.microsoft.com/en-us/office/vba/api/Access.Form.TimerInterval
Ronald de Boer OP  @Reply  
      
2 years ago
Thx for the above suggestions but I have found I need to run some code before the OnOpen event for the form.  It looks as though nothing is available.  I am going to try to Open a Form, run the code, run this form and close the first form automatically.  Seems dumb to me but I can't see any other way.

Suggestions welcome!

Regards and Thx

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Developer Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 5/1/2026 10:33:42 PM. PLT: 0s