Dlookup checkbox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Tidy
    New Member
    • Feb 2010
    • 6

    Dlookup checkbox

    Thanks in advance..Beginn er 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)
    Code:
    Dim Timesheet As string (Not sure on this at all)
    
    Timesheet = DLookup("[Correct]", "tbl_Daily Timesheet", "user ID = forms!frm_main!user_id")
    
    If Timesheet = False Then
    Last edited by NeoPa; Feb 25 '10, 01:45 AM. Reason: Please use the [CODE] tags provided
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32656

    #2
    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.

    Comment

    • Tidy
      New Member
      • Feb 2010
      • 6

      #3
      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("Corre ct") on form("Daily Timesheet"). If user has ticked it, it will open switchboard. If user has not ticked checkbox("Corre ct") on form("Daily Timesheet") it will open form("Daily Timesheet").
      Thanks

      Comment

      • missinglinq
        Recognized Expert Specialist
        • Nov 2006
        • 3533

        #4
        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)>

        Comment

        • Tidy
          New Member
          • Feb 2010
          • 6

          #5
          When I run it I get "Object does not support this property or method"

          Comment

          • Tidy
            New Member
            • Feb 2010
            • 6

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

            Sorry...I read the posting guidelines...Wi ll post code correctly now

            Comment

            • Tidy
              New Member
              • Feb 2010
              • 6

              #7
              Code:
               Case 2
              Select Case access_level
              Case 1 ' level1 menu
              ' validate password expiry
              password_period = DLookup("[password_date]", "tbl_users", "user_id =                 forms!frm_main!user_id")
                           If password_period < Date - 30 Then
                           strMsg = " Your password has expired. You must change your password"
                           MsgBox strMsg, vbInformation, "Expired Password"
                           DoCmd.OpenForm "frm_change_password", acNormal
                                      
                           Else
                                          
                           Timesheet = DLookup("[Correct]", "tbl_Daily Timesheet", "tbl_users", "user ID = forms!frm_main!user_id")
                            If IsNull(Timesheet) Then
                                    
                                                                                           
                             DoCmd.Minimize
                             DoCmd.OpenForm "Daily Timesheet"
                                          
                             Else
                                                                    
                             DoCmd.OpenForm "Level 1 Main Menu"
                             DoCmd.Close acForm, "frm_main", acSaveNo
                                          
                             End If 
                             End If

              Comment

              • NeoPa
                Recognized Expert Moderator MVP
                • Oct 2006
                • 32656

                #8
                Originally posted by Tidy
                When I run it I get "Object does not support this property or method"
                Can you confirm that this error message appears when executing line #13 from your code posted in post #7?

                Comment

                • NeoPa
                  Recognized Expert Moderator MVP
                  • Oct 2006
                  • 32656

                  #9
                  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).

                  Comment

                  • Tidy
                    New Member
                    • Feb 2010
                    • 6

                    #10
                    It seems once again NeoPa has nailed the issue if not the total solution..Thank you... Here is how it works...
                    Code:
                    Case 2
                      Select Case access_level
                       Case 1 ' level1 menu
                          ' validate password expiry
                           password_period = DLookup("[password_date]", "tbl_users", "user_id = forms!frm_main!user_id")
                           If password_period < Date - 30 Then
                               strMsg = " Your password has expired. You must change your password"
                               MsgBox strMsg, vbInformation, "Expired Password"
                                DoCmd.OpenForm "frm_change_password", acNormal
                                  
                                Else
                                                                                              
                                                                                              
                                Dim Correct As Variant
                                Correct = DLookup("[Correct]", "Daily Timesheet", "[user ID] = forms!frm_main!user_id")
                                If Correct = False Then
                               
                                DoCmd.Minimize
                                DoCmd.OpenForm "Daily Timesheet"
                                    
                                Else
                             
                    
                                DoCmd.OpenForm "Level 1 Main Menu"
                                DoCmd.Close acForm, "frm_main", acSaveNo
                                End If
                                
                                End If
                    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..

                    Comment

                    • NeoPa
                      Recognized Expert Moderator MVP
                      • Oct 2006
                      • 32656

                      #11
                      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)).

                      Comment

                      • TheSmileyCoder
                        Recognized Expert Moderator Top Contributor
                        • Dec 2009
                        • 2322

                        #12
                        If you want to loop through a records I would suggest opening a recordset.
                        Code:
                        Dim myRS As DAO.Recordset
                        Set myRS = CurrentDb.OpenRecordset("SELECT * FROM [Daily Timesheet] WHERE [user ID] = forms!frm_main!user_id", dbOpenDynaset)
                          
                        Do Until myRS.EOF
                         If myRS![Correct] Then
                           'Do your stuff
                         End If
                          
                          myRS.MoveNext
                        Loop

                        Comment

                        • Timesheet UK

                          #13
                          This post is very nice, Because your post is giving very nice information. So we are very thankful to you.

                          Comment

                          Working...