Page 2 of 2 FirstFirst 12
Results 16 to 27 of 27
  1. #16
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917

    All you need is a WhereCondition argument in your OpenReport command. You could use another button or just the Click or DoubleClick event of a control to launch the report. Just moving the focus to the record on the SubForm makes that record the Current record so getting to the ID field is easy.

  2. #17
    timmy is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    62
    thought so, i already did something similar, just have to base it on the subform using ID's now.

    Thanks so much for your help.

  3. #18
    timmy is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    62
    ok... having trouble filtering the report by serial number.

    i know how to filter it, but thats using a specific number i enter in the macro.

    I need it to look at the serial number field and filter it based on that.

    any help (again)?

    thanks.

  4. #19
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    Post your OpenReport code so we can see it.

  5. #20
    timmy is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    62
    I'm just using a macro to be honest, but heres the code when i convert it:

    Function Macro11()
    DoCmd.OpenReport "Meter Readings", acViewReport, "", "[Serial Number]", acNormal
    End Function


    All ive done is, in the WhereCondition field of the macro, i've typed [Serial Number]. I thought it would just select the records that match whatever is in the Serial Number field on the form.

  6. #21
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    Nope...that is not how it works. You will need to expand the WhereCondition argument to something like:
    "[Serial Number] = '" & [Serial Number] & "'"
    ...assuming the current and next form both have a field named [Serial Number] and it is a string value (which it should be as no math is ever performed on it).

  7. #22
    timmy is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    62
    Thanks for replying ruralguy, i tried that wherecondition and nothing happens... it just loads the report and lists all the machines regardless, it does have a filter on as the button for filter is depressed (switching on and off makes no difference).

    Both tables have a Serial Number field and yes they are both string values, any idea whats going wrong?

    Not sure if it matters, but a machines serial number can be a mixture of numbers and letters.

  8. #23
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    Is your button now executing the code instead of the Macro? If so then we can insert a MsgBox to display the WhereCondition argument before calling the Report.
    Code:
    Function Macro11()
    Dim MyWhere As String
    MyWhere = "[Serial Number] = '" & [Serial Number] & "'"
    MsgBox "[" & MyWhere & "]" '<-- this will display the WhereCondition
    DoCmd.OpenReport "Meter Readings", acViewReport, "", MyWhere, acNormal
    End Function

  9. #24
    timmy is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    62
    No, im using a macro and just entering "[Serial Number] = '" & [Serial Number] & "'"
    into the wherecondition field. I just tried changing it to a code, but im getting errors of all sorts (im really no good at coding anything past html...)

    heres my attempt at the code, the first bit im not sure what it is or why its there:

    Private Sub Form_Load()
    If Me.OpenArgs = "GotoNew" And Not IsNull(Me![PartID]) Then
    DoCmd.DoMenuItem acFormBar, 3, 0, , acMenuVer70
    End If
    End Sub

    Private Sub Meterreadingbut_Click()
    Function Macro1()
    Dim MyWhere As String
    MyWhere = "[Serial Number] = '" & [Serial Number] & "'"
    MsgBox "[" & MyWhere & "]" '<-- this will display the WhereCondition
    DoCmd.OpenReport "Meter Readings", acViewReport, "", MyWhere, acNormal
    End Function
    End Sub

    I would much rather use macros, if its possible.

  10. #25
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    I have almost no experience using macros. Since you can not have a Function inside of a Sub, do the following:
    Code:
    Private Sub Meterreadingbut_Click()
    '-- Function Macro1() <-- Rem out this line
    Dim MyWhere As String
    MyWhere = "[Serial Number] = '" & [Serial Number] & "'"
    MsgBox "[" & MyWhere & "]" '<-- this will display the WhereCondition
    DoCmd.OpenReport "Meter Readings", acViewReport, "", MyWhere, acNormal
    '-- End Function n <-- and rem out this line
    End Sub

  11. #26
    timmy is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    62
    oh wow.... it actually worked!

    thank you so much ruralguy, you are a wizard

  12. #27
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    I'm sure this can be done with a Macro as well but I'm not much help there, sorry. Maybe now that you know it can be done, you will have better success with a Macro. Thanks for posting back with your success and have fun.

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

Similar Threads

  1. Command buttons to Open Forms
    By Ace Pioneer in forum Access
    Replies: 1
    Last Post: 11-30-2010, 06:32 AM
  2. command buttons
    By nashr1928 in forum Forms
    Replies: 23
    Last Post: 10-15-2010, 04:09 PM
  3. Command buttons
    By maintt in forum Forms
    Replies: 3
    Last Post: 08-03-2010, 09:52 AM
  4. Moving Command Buttons
    By Pete Cope in forum Forms
    Replies: 0
    Last Post: 03-23-2010, 03:21 PM
  5. Access 2007 Command Buttons
    By fgerald in forum Access
    Replies: 2
    Last Post: 03-05-2010, 07:09 PM

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