Results 1 to 3 of 3
  1. #1
    Lounger
    Join Date
    Feb 2001
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have a work order database that I would like to be able to display the same form with different parameters. For instance, I would like to display a form with a particular work order number (using a combox box and a command button) entered on a separate form. I may also like to see this same form with a parameters of only the work orders that I created or only the workorders that I am assigned. I currently do this with separate queries attached to separate forms (identical except for the names and the query attached). Is there a better way to do this? Its very cumbersome when I need to make a change to the form and have to do it across all the separate forms. I need to use forms, because the end user needs to be able to update the information while viewing - I can't use reports. I feel like I'm missing something really simple. Below is what I am using. Is there some way to use the same document name, yet pass a query that has the needed parameter? Any ideas? Thanks in advance for your help!


    Private Sub WOViewByNumber_Click()
    On Error GoTo Err_WOViewByNumber_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "FRMWOView"

    stLinkCriteria = "[WorkOrderNumber]=" & Me![Work Order Number]
    DoCmd.OpenForm stDocName, , , stLinkCriteria

    Exit_WOViewByNumber_Click:
    Exit Sub

    Err_WOViewByNumber_Click:
    MsgBox Err.Description
    Resume Exit_WOViewByNumber_Click

    End Sub

  2. #2
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,434
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    Quote Originally Posted by Linda C. View Post
    Private Sub WOViewByNumber_Click()
    On Error GoTo Err_WOViewByNumber_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "FRMWOView"

    stLinkCriteria = "[WorkOrderNumber]=" & Me![Work Order Number]
    DoCmd.OpenForm stDocName, , , stLinkCriteria

    Exit_WOViewByNumber_Click:
    Exit Sub

    Err_WOViewByNumber_Click:
    MsgBox Err.Description
    Resume Exit_WOViewByNumber_Click

    End Sub
    Linda,

    From your description it would seem to me that all you have to do is to add fields (user name, etc) & buttons (Work Orders Originated by Me, Work Orders Assigned to Me) to the initial form to select the necessary criteria for the filter and replicate the code above for each button substituting the correct stLinkCriteria = command, ex: "[WorkOrderOriginator]=" & Me![UserName]

    Of course you could get fancy and have each button just construct the stLinkCriteria and then pass it to a generalized routine... saving the replication of the rest of the code.

    RG
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  3. #3
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts
    Quote Originally Posted by Linda C. View Post
    stLinkCriteria = "[WorkOrderNumber]=" & Me![Work Order Number]
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    I agree with what RG has said. Just to amplify a bit.

    The lines above that you use to open the form apply a filter. This acts like an extra criterion has been added (temporarily) to the form's query.
    Opening forms with filters provides great flexibility, because you can base the form on a very general query that returns all records, then open it with a range of different filters, according to the needs of the situation.
    Regards
    John



Posting Permissions

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