By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,480 Members | 2,189 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,480 IT Pros & Developers. It's quick & easy.

Dlookup checkbox

P: 6
Thanks in advance..Beginner here :)

I want to run a Dlookup on a checkbox and depending on the result open a specific form.
I know this should be easy but im stuck.
Info is
Table Name - Daily Timesheet
Checkbox Name - Correct

Have tried this...(and other things)
Expand|Select|Wrap|Line Numbers
  1. Dim Timesheet As string (Not sure on this at all)
  2.  
  3. Timesheet = DLookup("[Correct]", "tbl_Daily Timesheet", "user ID = forms!frm_main!user_id")
  4.  
  5. If Timesheet = False Then
Feb 25 '10 #1

✓ answered by NeoPa

Looking more closely at that line (line #13 from post #7) it appears that you are trying to give four parameter values to the DLookup() function, which only expects three. It seems that you give it two values for the Domain (table name).

Share this Question
Share on Google+
12 Replies


NeoPa
Expert Mod 15k+
P: 31,186
What you're trying to do precisely, is not clear. Precision and clarity are quite important as we cannot see your problem or your database.

Give us a hand to understand better what you're after and I'm sure we can help.
Feb 25 '10 #2

P: 6
Sorry if a bit vague on description..

I have a form (frm_main) that when a user clicks button the code(DLookup) will look to see if the user has already ticked checkbox("Correct") on form("Daily Timesheet"). If user has ticked it, it will open switchboard. If user has not ticked checkbox("Correct") on form("Daily Timesheet") it will open form("Daily Timesheet").
Thanks
Feb 25 '10 #3

missinglinq
Expert 2.5K+
P: 3,532
Also, what happened when you tried the code you gave? Nothing? Did you get an error message and if so, what was it?

In line with what NeoPa said, remember, you can see your database but we can't.

Welcome to Bytes!

Linq ;0)>
Feb 25 '10 #4

P: 6
When I run it I get "Object does not support this property or method"
Feb 25 '10 #5

P: 6
Also how do I use [code] Tags so I can post more of the code..

Sorry...I read the posting guidelines...Will post code correctly now
Feb 25 '10 #6

P: 6
Expand|Select|Wrap|Line Numbers
  1.  Case 2
  2. Select Case access_level
  3. Case 1 ' level1 menu
  4. ' validate password expiry
  5. password_period = DLookup("[password_date]", "tbl_users", "user_id =                 forms!frm_main!user_id")
  6.              If password_period < Date - 30 Then
  7.              strMsg = " Your password has expired. You must change your password"
  8.              MsgBox strMsg, vbInformation, "Expired Password"
  9.              DoCmd.OpenForm "frm_change_password", acNormal
  10.  
  11.              Else
  12.  
  13.              Timesheet = DLookup("[Correct]", "tbl_Daily Timesheet", "tbl_users", "user ID = forms!frm_main!user_id")
  14.               If IsNull(Timesheet) Then
  15.  
  16.  
  17.                DoCmd.Minimize
  18.                DoCmd.OpenForm "Daily Timesheet"
  19.  
  20.                Else
  21.  
  22.                DoCmd.OpenForm "Level 1 Main Menu"
  23.                DoCmd.Close acForm, "frm_main", acSaveNo
  24.  
  25.                End If 
  26.                End If 
Feb 25 '10 #7

NeoPa
Expert Mod 15k+
P: 31,186
@Tidy
Can you confirm that this error message appears when executing line #13 from your code posted in post #7?
Feb 25 '10 #8

NeoPa
Expert Mod 15k+
P: 31,186
Looking more closely at that line (line #13 from post #7) it appears that you are trying to give four parameter values to the DLookup() function, which only expects three. It seems that you give it two values for the Domain (table name).
Feb 25 '10 #9

P: 6
It seems once again NeoPa has nailed the issue if not the total solution..Thank you... Here is how it works...
Expand|Select|Wrap|Line Numbers
  1. Case 2
  2.   Select Case access_level
  3.    Case 1 ' level1 menu
  4.       ' validate password expiry
  5.        password_period = DLookup("[password_date]", "tbl_users", "user_id = forms!frm_main!user_id")
  6.        If password_period < Date - 30 Then
  7.            strMsg = " Your password has expired. You must change your password"
  8.            MsgBox strMsg, vbInformation, "Expired Password"
  9.             DoCmd.OpenForm "frm_change_password", acNormal
  10.  
  11.             Else
  12.  
  13.  
  14.             Dim Correct As Variant
  15.             Correct = DLookup("[Correct]", "Daily Timesheet", "[user ID] = forms!frm_main!user_id")
  16.             If Correct = False Then
  17.  
  18.             DoCmd.Minimize
  19.             DoCmd.OpenForm "Daily Timesheet"
  20.  
  21.             Else
  22.  
  23.  
  24.             DoCmd.OpenForm "Level 1 Main Menu"
  25.             DoCmd.Close acForm, "frm_main", acSaveNo
  26.             End If
  27.  
  28.             End If
  29.  
However... the dlookup is only finding the first record. Now I need it to loop somehow and check all [Correct] records for the user.
Any ideas :) ... Thanks again

P,s sorry if I dont explain these things well..
Feb 26 '10 #10

NeoPa
Expert Mod 15k+
P: 31,186
It's hard to be sure from what little you tell us, but I'm guessing you'll need to use a Recordset rather than DLookup(). That all depends on what you want to do with the multiple records you may find in [Daily Timesheet] for the matching [User ID] (or is it [User_ID]? Your code seems to use both (which I found a little confusing)).
Feb 26 '10 #11

TheSmileyCoder
Expert Mod 100+
P: 2,321
If you want to loop through a records I would suggest opening a recordset.
Expand|Select|Wrap|Line Numbers
  1. Dim myRS As DAO.Recordset
  2. Set myRS = CurrentDb.OpenRecordset("SELECT * FROM [Daily Timesheet] WHERE [user ID] = forms!frm_main!user_id", dbOpenDynaset)
  3.  
  4. Do Until myRS.EOF
  5.  If myRS![Correct] Then
  6.    'Do your stuff
  7.  End If
  8.  
  9.   myRS.MoveNext
  10. Loop
Feb 26 '10 #12

P: n/a
This post is very nice, Because your post is giving very nice information. So we are very thankful to you.
Oct 6 '10 #13

Post your reply

Sign in to post your reply or Sign up for a free account.