2016-07-28 10 views
0

Ich muss die Vorgänge in einem Konto zu einem bestimmten Zeitpunkt überprüfen, indem ich den Benutzer zur Eingabe der Kontonummer und des Datumsbereichs auffordere. Ich erhalte jedoch jedes Mal den Fehler "type mismatch "Anzeigen von Kontovorgängen nach Datum

Hier ist der Code:

Private Sub cmdSearch_Click() 
    Call search 
End Sub 

Sub search() 
    Dim strCriteria, strCount, task As String 

    Me.Refresh 
    If IsNull(Me.compte_hist) Or IsNull(Me.date_deb) Or IsNull(Me.date_fin) Then 
     MsgBox "s'il vous plaît assurez-vous que tous les champs sont remplis", vbInformation, "Date Range Required" 
     Me.compte_hist.SetFocus 
    Else 
     strCriteria = "([Date_operation]>= #" & Me.date_deb & "# And [Date_operation] <= #" & Me.date_fin & "#)" 
     strCount = "[Compte]=#" & Me.compte_hist & "#" 
     task = "select * from Operations where Operations (" & strCriteria & ")" And " (" & strCount & ") order by [Date_operation]" 
     DoCmd.ApplyFilter task 
    End If 
End Sub 
+1

Freundliche Anmerkung, 'strCriteria' und' strCount' sind Varianten. siehe [doc] (http://stackoverflow.com/documentation/vba/877/declaring-variables/2957/dim#t=201607281239547850873) – litelite

Antwort

2

Try this:

strCriteria = "([Date_operation]>= #" & Format(Me.date_deb, "mm\/dd\/yyyy") & "# And [Date_operation] <= #" & Format(Me.date_fin, "mm\/dd\/yyyy") & "#)" 
strCount = "[Compte]=" & Me.compte_hist 
task = "select * from Operations where (" & strCriteria & ") And (" & strCount & ") order by [Date_operation]" 
Me.RecordSource = task 

Sie können auch Filter anwenden nur:

strCriteria = "([Date_operation]>= #" & Format(Me.date_deb, "mm\/dd\/yyyy") & "# And [Date_operation] <= #" & Format(Me.date_fin, "mm\/dd\/yyyy") & "#)" 
strCount = "[Compte]=" & Me.compte_hist 
task = "(" & strCriteria & ") And (" & strCount & ")" 
Me.Filter = task 
Me.FilterOn = True 

Wenn Kontonummer nicht numerisch ist, verwenden Zitate:

strCount = "[Compte]='" & Me.compte_hist & "'"