2016-07-28 1 views
0

사용자에게 계정 번호와 날짜 범위를 입력하도록 요청하여 특정 기간에 계정에서 수행 된 작업을 확인해야하지만 실행할 때마다 "유형 불일치날짜별로 계정 작업 표시

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

친절한 메모를,'strCriteria'와'strCount'은 변종이다. [doc] (http://stackoverflow.com/documentation/vba/877/declaring-variables/2957/dim#t=201607281239547850873)를 참조하십시오. – litelite

답변

2

이 시도 :

0 : 만 필터를 적용 할 수 있습니다 또한

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 

를 "여기

코드입니다 계좌 번호는 숫자가 아닌 경우
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 

는 따옴표 사용

strCount = "[Compte]='" & Me.compte_hist & "'" 
관련 문제