Results 1 to 5 of 5
  1. #1
    nigelbloomy is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jul 2012
    Posts
    51

    Image visible if listed in a subform

    In Access 2010 I have a form that has a persons name. The form also has a subform that lists all of the people who "voted" for the record currently viewed. The subform has a parent child relationship setup so for each record it updates to show the votes for that record. I know this is corny, but I would like a picture to appear if the persons name on the main form (TxtCurrUser) also shows up in the list in the subform of those who voted for that record. The code below works only if the persons name shows up at the top of the list in the subform. How can I edit this to search the whole list? I've read through a lot of posts and it seems like this is simple, but I haven't been able to get it to work.



    Code:
    If TxtCurrUser = Me.WhoVotedSubform!UserVote Then
            'Me.HeartPic.Visible = True
        'Else
            'Me.HeartPic.Visible = False
        'End If

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    Don't understand the form/subform setup. What is the relationship? Why is person's name on both the main and subform?

    What event is the code in?

    Use RecordsetClone to search the subform records.

    With Me.subformname.RecordsetClone
    .FindFirst "PersonID=" & Me.PersonID
    Me.HeartPic.Visible = Not .NoMatch
    End With
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    nigelbloomy is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jul 2012
    Posts
    51
    The main form has information about an idea. It has the name of the person looking at the data and it has a button so the user can vote for the idea. That button fills a table with the name of the person and the unique number of the idea. The subform is a small box that lists the names of the people that have voted for an idea already. It is running a query off the table with the name and idea number. The subform is linked to the main form by the idea numbers.
    As a user moves through the list of ideas, I want the picture to show up if they have already voted for the idea. If they have voted for the idea, it should show up in both the main form and in the subform. Maybe there is an easier way to search for if the user has voted already.

    I tried your code and got an error stating that recordset is not an available method or domain. That's probably because I didn't describe very well how the form was set up.

  4. #4
    nigelbloomy is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jul 2012
    Posts
    51

    Other way to do it

    Talking through the real problem in the previous post led me to try a different approach. Instead of looking at the subform, I can query the table directly to see if the user has already voted.

    Code:
        User = Forms![Idea Form]![TxtCurrUser]
        IdeaID = Forms![Idea Form]![ID]
        Debug.Print "User = "; User
        
        stQuery = "SELECT Votes.IdeaID, Votes.UserVote " & _
                    "FROM Votes WHERE (((Votes.IdeaID)= " & IdeaID & ") " & _
                    "AND ((Votes.UserVote)= '" & User & "'));"
        Set rsQuery = CurrentDb.OpenRecordset(stQuery, dbOpenDynaset)
        
        iRecords = rsQuery.RecordCount
        Debug.Print "records = "; iRecords
        
        If iRecords = 0 Then
            Me.HeartPic.Visible = False
        Else
            Me.HeartPic.Visible = True
        End If

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    Another version of code uses DLookup domain aggregate function. No need for recordset.

    Me.HeartPic.Visible = Not IsNull(DLookup("IdeaID","Votes","IdeaID=" & Me.IdeaID & " AND UserVote='" & Me.User & "'"))
    Last edited by June7; 12-21-2012 at 01:22 AM.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Macro for visible field in subform
    By g=2012 in forum Access
    Replies: 7
    Last Post: 09-11-2012, 02:23 PM
  2. Replies: 5
    Last Post: 04-06-2012, 10:59 AM
  3. Visible property in subform columns
    By MDB in forum Forms
    Replies: 3
    Last Post: 09-03-2011, 06:46 PM
  4. Making subform field visible/invisible
    By Snufflz in forum Forms
    Replies: 3
    Last Post: 01-17-2011, 05:30 AM
  5. Replies: 2
    Last Post: 01-06-2011, 04:38 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