Results 1 to 12 of 12
  1. #1
    boboivan is offline Advanced Beginner
    Windows 7 32bit Access 2013
    Join Date
    Dec 2015
    Posts
    65

    find if tempVars value matches with a value in a subform

    Hello everyone!



    I need to hide 2 subforms in a form, if the current user is not listed in the 3rd query subform type.
    The name of the current user is in TempVars("CurrentUser").

    I've tried so far in On Current form section:

    Code:
    If DLookup("UserName", "Subform3", "UserName=" & TempVars("CurrentUser") & "") = True Then
       Me.Subform1.Visible = True
       Me.Subform2.Visible = True
    Else
       Me.Subform1.Visible = False
       Me.Subform2.Visible = False
    End if
    but with no luck.

    Any ideas?
    Thx a lot!

  2. #2
    orange's Avatar
    orange is online now Moderator
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    Please tell us more about
    the 3rd query subform type
    What exactly is Subform3?

    Detail syntax for DLookup()

    good luck

  3. #3
    boboivan is offline Advanced Beginner
    Windows 7 32bit Access 2013
    Join Date
    Dec 2015
    Posts
    65
    Subform3 is a list of users made from a query, that can see and edit the current record.

  4. #4
    orange's Avatar
    orange is online now Moderator
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    Please show the SQL of the query Subforms3.
    What is the value of TempVars("currentuser")?

    but with no luck.
    Are you getting an error from Access?

  5. #5
    boboivan is offline Advanced Beginner
    Windows 7 32bit Access 2013
    Join Date
    Dec 2015
    Posts
    65
    yes! I get an error msgbox from Access. I guess the error is because it should be a table name there, not a Subform name, as far as I could see. In this case, maybe is not a good idea to use dlookup function. What else I could use?
    The value of the TempVars("currentuser") is the name of the user that is signed in at that moment. It is a variable value.
    The query is made in order to filter the users who can see and edit each specific record in the form.

  6. #6
    orange's Avatar
    orange is online now Moderator
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    Please post the SQL for query Subform3?

    Also add a line

    Debug.Print TempVars("CurrentUser") before your If statement
    so we can see the value that Access sees.

    See what gets printed to the immediate window.

  7. #7
    boboivan is offline Advanced Beginner
    Windows 7 32bit Access 2013
    Join Date
    Dec 2015
    Posts
    65
    the SQL is
    Last edited by boboivan; 02-21-2016 at 03:18 AM.

  8. #8
    orange's Avatar
    orange is online now Moderator
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    It appears that there may be a missing space before FROM

    SELECT StructuriDeInterventieEvenimente.StructuraDeInterv entie, DefinireEvenimente.Eveniment, EvenimenteLunare.EvenimentLunar, StructuriDeInterventieEvenimente.IDevenimentFROM (StructuriDeInterventieEvenimente INNER JOIN DefinireEvenimente ON StructuriDeInterventieEvenimente.IDeveniment = DefinireEvenimente.IDeveniment) INNER JOIN EvenimenteLunare ON DefinireEvenimente.IDeveniment = EvenimenteLunare.EvenimentLunar
    GROUP BY StructuriDeInterventieEvenimente.StructuraDeInterv entie, DefinireEvenimente.Eveniment, EvenimenteLunare.EvenimentLunar, StructuriDeInterventieEvenimente.IDeveniment
    ORDER BY StructuriDeInterventieEvenimente.IDeveniment;


    Formatted SQL
    Code:
    SELECT StructuriDeInterventieEvenimente.StructuraDeInterventie
        ,DefinireEvenimente.Eveniment
        ,EvenimenteLunare.EvenimentLunar
        ,StructuriDeInterventieEvenimente.IDeveniment
    FROM (
        StructuriDeInterventieEvenimente INNER JOIN DefinireEvenimente ON
        StructuriDeInterventieEvenimente.IDeveniment = DefinireEvenimente.IDeveniment
        )
    INNER JOIN EvenimenteLunare ON 
        DefinireEvenimente.IDeveniment = EvenimenteLunare.EvenimentLunar
    GROUP BY StructuriDeInterventieEvenimente.StructuraDeInterventie
        ,DefinireEvenimente.Eveniment
        ,EvenimenteLunare.EvenimentLunar
        ,StructuriDeInterventieEvenimente.IDeveniment
    ORDER BY StructuriDeInterventieEvenimente.IDeveniment;

  9. #9
    boboivan is offline Advanced Beginner
    Windows 7 32bit Access 2013
    Join Date
    Dec 2015
    Posts
    65
    I've just copied it and pasted it. It seems like it didn't take the space there. It is a space, of course.
    Last edited by boboivan; 02-21-2016 at 03:17 AM.

  10. #10
    orange's Avatar
    orange is online now Moderator
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    Yes, DLookup is expecting a table or query name -not a subform.

    Any update based on the Debug.Print TempVars("CurrentUser")

  11. #11
    boboivan is offline Advanced Beginner
    Windows 7 32bit Access 2013
    Join Date
    Dec 2015
    Posts
    65
    Quote Originally Posted by orange View Post
    Any update based on the Debug.Print TempVars("CurrentUser")
    I don't know what you mean. The TempVars("CurrentUser") value is the name of the user that is loged in. It is a variable value.

    On the other hand, I don't know why is so difficult for access to lookup for a value in a subform. It seems like a pretty decent thing to do
    By the way, the subform has now the Record Source a table, not a query.

  12. #12
    boboivan is offline Advanced Beginner
    Windows 7 32bit Access 2013
    Join Date
    Dec 2015
    Posts
    65
    I could find a solution for my problem.

    Code:
    If (TempVars("CurrentUser") = DLookup("Table/QueryFieldNameToLookUp", "Table/QueryName", "IDrecordInTheTable/Query=" & "IDrecordWhereIsTheSubform3" & " And [FieldNameOfSubform3] = '" & TempVars("CurrentUser") & "'")) Then ...

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Query to find Partial Match of Column Data
    By rachmorr9 in forum Queries
    Replies: 2
    Last Post: 09-22-2015, 09:09 PM
  2. Replies: 2
    Last Post: 07-27-2015, 06:53 AM
  3. Replies: 4
    Last Post: 07-24-2015, 02:11 AM
  4. Replies: 11
    Last Post: 02-06-2014, 10:05 PM
  5. Find an Exact Match in a Access Table column
    By raghavendran in forum Access
    Replies: 4
    Last Post: 10-12-2013, 11:57 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums