Formatting control on form open

ChuckRobert

Board Regular
Joined
Feb 26, 2009
Messages
64
When logging into my program, user information is captured in a query. I am trying to access that with a DLookup as the form loads so I can use those values to determine which buttons and text boxes are to be enabled. The problem is that the form loads before the DLookup is captured by the form load event. Here is a sample of my code:

Code:
[COLOR=black][FONT=Times New Roman]Option Compare Database<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman]Option Explicit<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman]<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman]Private Sub Form_Load()<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman]<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman]Dim rank As String<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman]Dim shift As Integer<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman]Dim assign As String<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman]<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman]rank = DLookup("[LastOfLogIn_Rank]", "qry_User")<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman]shift = DLookup("[LastOfLogIn_Shift]", "qry_User")<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman]assign = DLookup("[LastOfLogIn_Assignment]", "qry_User")<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman]<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman]‘testing values onto temp text boxes on the form.  Displays previous, not currrent values in these test boxes.[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman]Me!txtRank = rank<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman]Me!txtshift = shift<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman]Me!txtAssign = assign<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman]<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman]If ((shift = "1") And (rank = "Cook") And (assign = "Kitchen")) Then<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman]<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman]Me!txtOne.Enabled = False<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman]Me!btnOne.Enabled = True<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman]<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman]End If<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman]End Sub<o:p></o:p>[/FONT][/COLOR]

If I close and reopen the form again, the DLookup properly confiures by controls I want enabled, or disabled. Can anyone offer a suggestion?
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
What's the name of the query that's the record source for the form?
 
Upvote 0
Norie,
Thanks for asking. I just double-checked my Login code, and I'm opening the Home page before writing the user info to the table/Query required by the DLookup on the Home page form. Thats' not going to work! I'll fix that later tonight, and follow up. Thanks again.
Chuck
 
Upvote 0
Norie,
It's working fine now. In the click event to check the password on the login form, I just had to close the login form before opening the home page. Thanks again for your time.

Chuck
 
Upvote 0

Forum statistics

Threads
1,224,592
Messages
6,179,789
Members
452,942
Latest member
VijayNewtoExcel

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