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

    find all values in a query

    Hi guys!



    I've created a query (TestQuery) in order to see all IDlead in my "TableTest", related to each ID in "PaperOut" table.

    Click image for larger version. 

Name:	Untitled.jpg 
Views:	46 
Size:	15.7 KB 
ID:	26802

    When I open the report for the "IDpaper" record 3 (from the form "PaperOut"), I need to see all the names of IDlead (1,2,5,6).
    For this, I've tried the following code, but it returns only the name of the first ID (1):

    Code:
    Private Sub Report_Load()
    If DLookup("IDlead", "TestQuery", "[IDpaper] =" & Forms("PaperOut").IDpaper) = 1 Then
    Me.Text17 = "the name of the leader 1"
    ElseIf DLookup("IDlead", "TestQuery", "[IDpaper] =" & Forms("PaperOut").IDpaper) = 2 Then
    Me.Text19 = "the name of the leader 2"
    ElseIf DLookup("IDlead", "TestQuery", "[IDpaper] =" & Forms("PaperOut").IDpaper) = 3 Then
    Me.Text20 = "the name of the leader 3"
    ElseIf DLookup("IDlead", "TestQuery", "[IDpaper] =" & Forms("PaperOut").IDpaper) = 4 Then
    Me.Text21 = "the name of the leader 4"
    ElseIf DLookup("IDlead", "TestQuery", "[IDpaper] =" & Forms("PaperOut").IDpaper) = 5 Then
    Me.Text22 = "the name of the leader 5"
    ElseIf DLookup("IDlead", "TestQuery", "[IDpaper] =" & Forms("PaperOut").IDpaper) = 6 Then
    Me.Text23 = "the name of the leader 6"
    End If
    End Sub
    Any help, please?

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    You don't use IIF statements.
    make a conversion table,this has the values and text to join to the other table.
    1, leader1
    2,leader2
    etc.

    Join the 2 tables in a query to get the results.
    no need for vb code.

  3. #3
    boboivan is offline Advanced Beginner
    Windows 7 32bit Access 2013
    Join Date
    Dec 2015
    Posts
    65
    Thx Ranman!

    Maybe I didn't make myself very clear.
    The point is that in my table I have a field with multiple values (ex: John, Beth, Ruth).
    When I open the report for the an specific record of my table (where I have these 3 options selected), I need to see all the choices, each in separated textboxes (in textbox19 to see John, in textbox20 Beth, in textbox 21 Ruth)
    How can I do that?

    Thx again!

  4. #4
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    The 'text boxes' would be records. John is 1 record, Mary is another record,etc.
    these would show as a data sheet in a subForm.
    This is how multi value data is shown.

  5. #5
    boboivan is offline Advanced Beginner
    Windows 7 32bit Access 2013
    Join Date
    Dec 2015
    Posts
    65
    I know that, but it doesn't help too much.
    I need each textbox to have additional info and different formats. I've set the textboxes as rich boxes in order to do that as I need.

  6. #6
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,511
    Can you use the OnFormat event in the detail section to do what you need. Make sure IDLead field is in the detail section. Maybe something like:

    If Me.IDlead = 1 Then
    Me.Text17 = "the name of the leader 1"
    ElseIf Me.IDlead = 2 Then
    Me.Text19 = "the name of the leader 2"
    ElseIf Me.IDlead = 3 Then
    Me.Text20 = "the name of the leader 3"
    ElseIf Me.IDlead = 4 Then
    Me.Text21 = "the name of the leader 4"
    ElseIf Me.IDlead = 5 Then
    Me.Text22 = "the name of the leader 5"
    ElseIf Me.IDlead = 6 Then
    Me.Text23 = "the name of the leader 6"
    End If

  7. #7
    boboivan is offline Advanced Beginner
    Windows 7 32bit Access 2013
    Join Date
    Dec 2015
    Posts
    65
    Thx Bulzie, but it doesn't work either.

  8. #8
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Can you post your db?

  9. #9
    boboivan is offline Advanced Beginner
    Windows 7 32bit Access 2013
    Join Date
    Dec 2015
    Posts
    65
    I've tried, but the size limit of the attached files on this site is max 500kB. My db is over this limit.

  10. #10
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2007
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    How about creating a record set to run through. Something like...

    Code:
    Option Compare Database
    
    Private Sub filltxts()
    
    Dim db As Database
    Dim rs As Recordset
    Set db = CurrentDb
    Set rs = db.OpenRecordset("TestQuery")
    Do Until EOF
    Select Case rs!IDPaper
    Case Is = 1
    Me.Text17 = "the name of the leader 1"
    Case Is = 2
    Me.Text19 = "the name of the leader 2"
    Case Is = 3
    Me.Text20 = "the name of the leader 3"
    Case Is = 4
    Me.Text21 = "the name of the leader 4"
    Case Is = 5
    Me.Text22 = "the name of the leader 5"
    Case Is = 6
    Me.Text23 = "the name of the leader 6"
    End Select
    rs.MoveNext
    Loop
    End If
    End Sub

  11. #11
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Quote Originally Posted by boboivan View Post
    I've tried, but the size limit of the attached files on this site is max 500kB. My db is over this limit.
    Do a "Compact & Repair", then Zip it. You should then be able to attach it to a post.


    The point is that in my table I have a field with multiple values (ex: John, Beth, Ruth).
    It sounds like you have used a multi-value field in a table. These type of fields are a real PITA (IMO) to use......

    You might see
    https://support.office.com/en-us/art...C-6DE9BEBBEC31
    and
    https://support.office.com/en-us/art...3-B6624E1E323A

  12. #12
    boboivan is offline Advanced Beginner
    Windows 7 32bit Access 2013
    Join Date
    Dec 2015
    Posts
    65
    Thx andy49!
    You got the point of my issue.
    Your code returns though a Compile error: Argument not optional, line: Do Until EOF
    Maybe it's because I didn't used the code in the right place.
    I took ssanfu advice and I've made a smaller size DB, in order to post it here. Check the attachment!

    Thx again!
    Happy new year!
    Attached Files Attached Files

  13. #13
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2007
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    Aha. Should be do until rs.eof

    Silly error!!

    I'll look on my laptop in the new year


    Sent from my iPhone using Tapatalk

  14. #14
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2007
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    The alternative (as you'll end up with empty text boxes) could be to have 6 text boxes text1, text2 etc.

    find how many records the query has (four for 1,4,5,6 as an example)



    Then set the value of the first four text boxes with me.txt1 = rs!idpaper

    And make the remaining (2) text boxes invisible

    Might look "neater" but not sure if that's what you're after


    Sent from my iPhone using Tapatalk

  15. #15
    boboivan is offline Advanced Beginner
    Windows 7 32bit Access 2013
    Join Date
    Dec 2015
    Posts
    65
    Now I get the Compile error: End if without block if: line End if
    I've took out the line and I get the Run-time error '3061': Too few parameters. Expected 1: line Set rs = db.OpenRecordset("TestQuery")

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 02-22-2016, 04:01 AM
  2. Replies: 3
    Last Post: 02-07-2016, 10:49 AM
  3. Query to find Values that do NOT exist
    By SoonerLater in forum Queries
    Replies: 4
    Last Post: 09-19-2015, 06:29 PM
  4. Find difference of values between dates
    By Miquel1 in forum Queries
    Replies: 8
    Last Post: 12-10-2013, 10:37 AM
  5. find out values between two dates column
    By learning_graccess in forum Queries
    Replies: 3
    Last Post: 04-20-2012, 04:17 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