Results 1 to 11 of 11

Thread: if then (xp)

  1. #1
    3 Star Lounger
    Join Date
    Feb 2004
    Location
    Kitchener, Ontario, Canada
    Posts
    228
    Thanks
    0
    Thanked 0 Times in 0 Posts

    if then (xp)

    I am trying to make an if.. then....else statement work for me and I am having a small problem. I want the statement to look at a table [Current User] this table will only have 1 record in it. I want to look at 1 field [Permission view and edit Login records] and if the value of the field is 1 then I want to do whats in the if statement.
    I have the tried
    If current_user.Permission_view_and_edit_Login_record s = 1 Then
    but nope.

  2. #2
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: if then (xp)

    I presume that this code is in VBA, in which case open a recordset and use that.

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: if then (xp)

    Or use DLookup:

    If DLookup("[Permission view and edit Login records]", "[Current User]") = 1 Then

  4. #4
    5 Star Lounger
    Join Date
    Apr 2003
    Location
    Hampshire, United Kingdom
    Posts
    602
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: if then (xp)

    There is an alternative to the way you're doing this. Instead of writing the current user's details to a table (and presumably deleting them on close) you could use global ("public") variables instead. That way they'd always be accessible to your VBA and you wouldn't have to read/write to/from the table every time someone opens or closes the database. Using global variables will also let you open your database to multiple users, whereas your method only allows for one user to be accessing the database at a time.

    For more information on variable access levels, see Access Levels in Visual Basic.
    Waggers
    If at first you do succeed, you've probably missed something.

  5. #5
    3 Star Lounger
    Join Date
    Feb 2004
    Location
    Kitchener, Ontario, Canada
    Posts
    228
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: if then (xp)

    Hans,

    I gave it a try like this
    ---------------------------------------------------------------------------
    Private Sub User_Administration_Click()
    On Error GoTo Err_User_Administration_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    If DLookup("[Permission view and edit Login records]", "[Current User]") = 1 Then

    stDocName = "User Administration"
    DoCmd.OpenForm stDocName, , , stLinkCriteria

    Else

    Call MsgBox("You are trying to access the administration acres for which you do not have access. Please see your system admin for access to this area.", vbCritical, "")

    Exit_User_Administration_Click:
    Exit Sub

    Err_User_Administration_Click:
    MsgBox Err.Description
    Resume Exit_User_Administration_Click

    End Sub
    -----------------------------------------------------------------

    when I press the button nothing... it does not open the form "User Administration" nor does it show me the msg box no matter what value I set in the table "Current User"

  6. #6
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: if then (xp)

    Firstly you are missing the End if before the Exit statement.

    Also I don't think you have the syntax of the dlookup right.

    The syntax is Dlookup(field, table, condition) where the condition is optional. If you need to find a specific record in the table use the condition. if there is only one record, or the first record will do, leave it out.

    Experiment with getting the Dlookup right before you try to use the result. So you could assign the result of the dlookup to a string variable, then just display this with a message box.
    Regards
    John



  7. #7
    3 Star Lounger
    Join Date
    Feb 2004
    Location
    Kitchener, Ontario, Canada
    Posts
    228
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: if then (xp)

    John,

    Thanks... it was the simple missing End if... the Dlookup was right. I added teh missing part and it worked like a charm... thanks for all the help.

  8. #8
    3 Star Lounger
    Join Date
    Feb 2004
    Location
    Kitchener, Ontario, Canada
    Posts
    228
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: if then (xp)

    Thanks for the help but I will not have access to this when the program is all done as I will not be the end user who has no idea of access...

  9. #9
    3 Star Lounger
    Join Date
    Feb 2004
    Location
    Kitchener, Ontario, Canada
    Posts
    228
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: if then (xp)

    Thanks for the help. I have no idea how to open a recordset. all I was missing was the End If command. again thanks

  10. #10
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: if then (xp)

    Cory mentioned that he has a table with a single record. So no condition is needed in the DLookup.

  11. #11
    5 Star Lounger
    Join Date
    Apr 2003
    Location
    Hampshire, United Kingdom
    Posts
    602
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: if then (xp)

    I know the feeling <img src=/S/smile.gif border=0 alt=smile width=15 height=15>
    Waggers
    If at first you do succeed, you&#39;ve probably missed something.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •