DoCmd.OpenForm and stLinkCriteria problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mark mestrom
    New Member
    • Jun 2007
    • 2

    DoCmd.OpenForm and stLinkCriteria problem

    hi, i have this problem with OpenForm and the stLinkCriteria. I have the following code:

    Code:
    [I]Private Sub Knop22_Click()
    On Error GoTo Err_Knop22_Click
    
        Dim stDocName As String
        Dim stLinkCriteria As String
    
        stDocName = "ALAHistorieEdit"
    
        stLinkCriteria = "[ALAHistorie]![Barcode]= " & Me![Barcode] & " And  _
                               [ALAHistorie]![Teller]= " & Me![Teller]
        DoCmd.OpenForm stDocName, , , stLinkCriteria
    
    Exit_Knop22_Click:
        Exit Sub
    
    Err_Knop22_Click:
        MsgBox Err.Description
        MsgBox Err.Number
        Resume Exit_Knop22_Click
        
    End Sub[/I]
    When i debug, the stLinkCriteria contains (for example) :
    "[ALAHistorie]![Barcode]= 12345 And [ALAHistorie]![Teller]= 2"

    Barcode and Teller (autonumberd counter) are numeric and the record does exist. But i keep getting error 2501, action openform cancelled. With only Barcode as criteria in stLinkCriteria the action succeeds but (logically) only with the first record with that Barcode.

    What am i doing wrong with the criteria for that seems to be the problem?

    Tanx,
    Mark
    Last edited by NeoPa; Jun 11 '07, 09:25 PM. Reason: Please use [CODE] tags
  • Lysander
    Recognized Expert Contributor
    • Apr 2007
    • 344

    #2
    Originally posted by mark mestrom
    hi, i have this problem with OpenForm and the stLinkCriteria. I have the following code:

    Private Sub Knop22_Click()
    On Error GoTo Err_Knop22_Clic k

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "ALAHistorieEdi t"

    stLinkCriteria = "[ALAHistorie]![Barcode]= " & Me![Barcode] & " And _
    [ALAHistorie]![Teller]= " & Me![Teller]
    DoCmd.OpenForm stDocName, , , stLinkCriteria

    Exit_Knop22_Cli ck:
    Exit Sub

    Err_Knop22_Clic k:
    MsgBox Err.Description
    MsgBox Err.Number
    Resume Exit_Knop22_Cli ck

    End Sub


    When i debug, the stLinkCriteria contains (for example) :
    "[ALAHistorie]![Barcode]= 12345 And [ALAHistorie]![Teller]= 2"

    Barcode and Teller (autonumberd counter) are numeric and the record does exist. But i keep getting error 2501, action openform cancelled. With only Barcode as criteria in stLinkCriteria the action succeeds but (logically) only with the first record with that Barcode.

    What am i doing wrong with the criteria for that seems to be the problem?

    Tanx,
    Mark
    What is the record source for the form ALAHistorieEdit ?

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32668

      #3
      Your continuation on line 9 is not a contiuation because it falls within your literal string.
      Try :
      Code:
      Private Sub Knop22_Click()
      On Error GoTo Err_Knop22_Click
      
          Dim stDocName As String
          Dim stLinkCriteria As String
      
          stDocName = "ALAHistorieEdit"
      
          stLinkCriteria = "[ALAHistorie]![Barcode]=" & Me![Barcode] & " And  " & _
                           "[ALAHistorie]![Teller]=" & Me![Teller]
          DoCmd.OpenForm stDocName, , , stLinkCriteria
      
      Exit_Knop22_Click:
          Exit Sub
      
      Err_Knop22_Click:
          MsgBox Err.Description
          MsgBox Err.Number
          Resume Exit_Knop22_Click
          
      End Sub

      Comment

      Working...