Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2007
    Posts
    102

    Unanswered: strLinkCriteria issues, need some guidance

    Hello from a newbie,

    I have a form with a subform that displays a listbox control called 'theOrderID'. I have set it up (height 4") so that a long list of "saved" orders displays on the Form. The navigation works, so a person can scroll through the list of past orders.
    I'm attempting to set up a way for the customer to search by date. (filter the past orders) and also to preview the order selected, and finally print.

    I've got the code worked out for the listbox. The filter by date sort of worked out with a valuelist called 'filter' (today, this week, lastweek, etc.) and a macro.
    I'm having the most difficulty with the preview and print.

    The main form is bound to query "Invoices"; shows 3 fields (in valuelist), Customer Name, OrderID and OrderDate.

    I have a Preview Button that calls a subroutine "Preview_Click---

    Code: ( text )
    Private Sub Preview_Click()
    Private Sub Preview_Click()
    Dim strDocName As String
    Dim strLinkCriteria As String

    On Error GoTo ErrorHandler

    If IsNull(OrderID) Then
    MsgBox "Please click an order in the list.", vbInformation
    Else
    Me.Visible = False
    strDocName = "Invoice"
    strLinkCriteria = "OrderID = " & OrderID
    DoCmd.OpenReport strDocName, acViewPreview, strLinkCriteria
    End If

    Exit Sub

    ErrorHandler:
    MsgBox "Error#: " & Err.Number & vbCrLf & Err.Description
    End Sub


    I can't get it to work. Invoice is a Report I created. Is there anyone that cna give me some solid directions ? thanks in advance....

    imrosie

  2. #2
    Join Date
    Jul 2003
    Location
    Michigan
    Posts
    1,941
    Hello,

    My first guess would be that your strLinkCriteria should read:

    strLinkCriteria = "OrderID = " & theOrderID

    You want to link to the value selected in the listbox, not the value
    from the OrderID field in the query.
    Inspiration Through Fermentation

  3. #3
    Join Date
    Feb 2006
    Posts
    60
    you might wanna try something like this;
    strLinkCriteria = "[OrderID] = " & OrderID
    the brackets help it define its a field. also, if the right hand OrderID is the name of a 'field' in your table that your form is linked to, put square brackets around ti too. only dont use the square brackest if its linking to a text box or combo box or something.

    Further to that, if your OrderID's have not been set as numbers in the tables, then you need to put the ' ' around it. so you would end up with;
    strLinkCriteria = "[OrderID] = '" & OrderID & "'"

  4. #4
    Join Date
    Dec 2003
    Location
    Dallas, TX
    Posts
    1,004

    Talking

    Quote Originally Posted by imrosie
    Hello from a newbie,

    I have a form with a subform that displays a listbox control called 'theOrderID'. I have set it up (height 4") so that a long list of "saved" orders displays on the Form. The navigation works, so a person can scroll through the list of past orders.
    I'm attempting to set up a way for the customer to search by date. (filter the past orders) and also to preview the order selected, and finally print.

    I've got the code worked out for the listbox. The filter by date sort of worked out with a valuelist called 'filter' (today, this week, lastweek, etc.) and a macro.
    I'm having the most difficulty with the preview and print.

    The main form is bound to query "Invoices"; shows 3 fields (in valuelist), Customer Name, OrderID and OrderDate.

    I have a Preview Button that calls a subroutine "Preview_Click---

    Code: ( text )
    Private Sub Preview_Click()
    Private Sub Preview_Click()
    Dim strDocName As String
    Dim strLinkCriteria As String

    On Error GoTo ErrorHandler

    If IsNull(OrderID) Then
    MsgBox "Please click an order in the list.", vbInformation
    Else
    Me.Visible = False
    strDocName = "Invoice"
    strLinkCriteria = "OrderID = " & OrderID
    DoCmd.OpenReport strDocName, acViewPreview, strLinkCriteria
    End If

    Exit Sub

    ErrorHandler:
    MsgBox "Error#: " & Err.Number & vbCrLf & Err.Description
    End Sub


    I can't get it to work. Invoice is a Report I created. Is there anyone that cna give me some solid directions ? thanks in advance....

    imrosie

    Hi Imrosie,

    Not sure if this helps but here is the code from one of my databases. See if it helps any:

    Code:
    Private Sub cmdVendorHours_Click()
    On Error GoTo Err_cmdVendorHours_Click
    
        Dim stDocName As String
        Dim stLinkCriteria As String
    
        stDocName = "frmVendorHours"
        
        stLinkCriteria = "[VendorID]=" & Me![VendorID]
        DoCmd.OpenForm stDocName, , , stLinkCriteria
    
    Exit_cmdVendorHours_Click:
        Exit Sub

Posting Permissions

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