Results 1 to 6 of 6
  1. #1
    4 Star Lounger
    Join Date
    Jan 2003
    Location
    Central Florida, USA
    Posts
    505
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Getting form control info into code (03)

    I have a form that has several check boxes on it. The check boxes are used to identify which report(s) to run. The user selects one or more check boxes and then clicks on a control to run the reports. I have a table with that contains the name of the checkbox control and the report name. My goal is to loop through the records, check to see if the chkbox is true, and then print the report if true.

    However, I am not able to figure out a way to identify the control/checkbox using the "me." syntax. The following is the code I am attempting to use. This may not be possible in code, but I figured if it could, you would know how to accomplish it. Any ideas?

    Dim db As DAO.Database
    Dim rst As DAO.Recordset
    Dim strSQL As String

    Set db = CurrentDb
    strSQL = "SELECT QueryName, ExcelName, ExportGroup " & _
    "FROM tlkpExportFields " & _
    "WHERE ExportGroup = 'pdf' " & _
    "ORDER BY pkey;"

    Set rst = db.OpenRecordset(strSQL, dbOpenSnapshot)
    With rst
    .MoveFirst
    Do While Not .EOF
    If Me.[!QueryName] = True Then
    DoCmd.OpenReport !ExcelName, acPreview
    End If
    .MoveNext
    Loop
    End With

    Thanks in advance for sharing.

    ken

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

    Re: Getting form control info into code (03)

    Try <code>Me.Controls(!QueryName)</code>

  3. #3
    4 Star Lounger
    Join Date
    Jan 2003
    Location
    Central Florida, USA
    Posts
    505
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Re: Getting form control info into code (03)

    Hans,
    I don't know why I can't find the easy things.

    THANKS!

    Ken

  4. #4
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Alzano Lombardo, Italy
    Posts
    1,483
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Getting form control info into code (03)

    Does the exclamation mark in front of QueryName have a purpose?

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

    Re: Getting form control info into code (03)

    Yes. The line is contained within a With ... End With block:
    <code>
    With rst
    ...
    If Me.Controls(!QueryName) = True Then
    ...
    End With
    </code>
    So !QueryName actually stands for rst!QueryName, which in itself is a shorthand notation for rst.Fields("QueryName").

  6. #6
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Alzano Lombardo, Italy
    Posts
    1,483
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Getting form control info into code (03)

    Thank you Hans <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

Posting Permissions

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