Results 1 to 8 of 8
  1. #1
    lzook88 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2015
    Posts
    75

    Auto Fill Label based upon query

    I have a query that runs and shows active members of a group. I am attempting to create an unbound form that has labels and combo boxes to enter multiple records into a table when submitted. The issue is the labels need to be the full names of the active members that the query pulls



    here is my vba code for this so far:

    Code:
    Private Sub Form_Load()
    Dim i As Integer
    Dim z As Integer
    
    'fill labels with active explorers
    
    For z = 1 To 25
        For i = 1 To 25
            Me.Controls("name" & i).Caption = DLookup("[Full Name]", "Explorers Query", "ID=" & z)
        Next i
    Next z
    
    End Sub
    would anyone be able to help me with this?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    What is the issue? If the code doesn't work, what is happening - error message, wrong results, nothing?

    The table name has a space, try enclosing with [] same as you did for the field.

    Advise no spaces or special characters/punctuation (underscore is exception) in naming convention.

    Why do you have nested loop? Seems to me the i loop is not needed. There are 25 label controls then just the z loop and reference z in both concatenations. But how will referencing the z index for the ID return the appropriate name?

    Open a recordset object and loop through the recordset

    Dim rs As DAO.Recordset, x As Integer
    Set rs = CurrentDb.OpenRecordset("SELECT [Full Name] FROM [Explorers Query] ORDER BY [Full Name];")
    x = 1
    While Not rs.EOF
    Me.Controls("name" & x).Caption = rs.[Full Name]
    rs.MoveNext
    x = x + 1
    Wend

    There will never be more than 25 records in the query?
    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
    lzook88 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2015
    Posts
    75
    With the above code used. Opening the form results with:

    Run-Time Error '13':
    Type Mismatch


    taking out the second variable and using the same variable for both results with:

    Run-Time Error '13':
    Type Mismatch

    adding the [] around the Explorers Query part also returns the Run-Time Mismatch error.


    when you press debug on all three ways it highlights

    Code:
    Me.Controls("name" & i).Caption = DLookup("[Full Name]", "Explorers Query", "ID=" & i)
    Code:
    Me.Controls("name" & i).Caption = DLookup("[Full Name]", "[Explorers Query]", "ID=" & i)

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    I edited my previous post probably while you were reading. Review again.
    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.

  5. #5
    lzook88 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2015
    Posts
    75
    And as of now no. We only accept 25 explorers on the roster at a time

  6. #6
    lzook88 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2015
    Posts
    75
    Okay I have updated my code to what you put:

    Code:
    Private Sub Form_Load()
    Dim rs As DAO.Recordset, x As Integer
    
    Set rs = CurrentDb.OpenRecordset("SELECT [FULL NAME] FROM [Explorers Query] ORDER BY [Full Name];")
    
    x = 1
    While Not rs.EOF
    Me.contorls("name" & x).Caption = rs.[FULL NAME]
    rs.MoveNext
    x = x + 1
    Wend
    
    End Sub
    when i load the form i am getting:

    Compile Error:
    Method or Data Member not found

    .[Full Name]


    I have attached the file in a ZIP folder

    Attachment 22013

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    First, need to spell Controls correctly.

    Second, my goof, use ! instead of . : rs![FULL NAME]
    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.

  8. #8
    lzook88 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2015
    Posts
    75
    The misspelling on Controls was my fault .. I had fixed it right after I posted on my coding. The "!" worked like a charm..

    Thanks for your assistance..
    Last edited by lzook88; 09-12-2015 at 03:02 AM. Reason: moved question to new thread

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

Similar Threads

  1. Replies: 1
    Last Post: 11-23-2014, 02:20 PM
  2. auto fill fields based on another field
    By dbell in forum Forms
    Replies: 18
    Last Post: 05-26-2014, 01:46 PM
  3. Replies: 3
    Last Post: 03-15-2013, 03:27 PM
  4. Replies: 2
    Last Post: 01-26-2013, 07:53 PM
  5. auto fill name based on file number
    By mark_w in forum Forms
    Replies: 13
    Last Post: 08-03-2012, 04:59 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