我有一個問題,在我單擊一個按鈕后,組合框回傳奇怪的值,該按鈕在該表單上執行查詢。
行源是在 VBA 中分配的,我檢查了 ST_Id 的值是否始終保持不變
這是VBA代碼:
Private Sub Form_Load()
dYear = Year(Now)
dMonth = Month(Now)
getDate = DateSerial(dYear, dMonth 1, 0) 'to get the last day of this month
ST_Id = DLookup("[ID]", "ReportingDays", "[ReportingDay] =#" & Format(getDate, "yyyy\/mm\/dd") & "#") 'returns the ID that is saved in ReportingDays-table
Forms!frm_Team!ReportingMonth.RowSource = "SELECT ReportingDays.ID, ReportingDays.MonthText FROM ReportingDays " _
& " WHERE ReportingDays.ID > " & ST_Id - 3 & " AND ReportingDays.ID < " & ST_Id 10 & ";" 'fills Combobox with values -2 and 9 months from the actual month
End Sub
當我第一次打開表單時,一切正常:

但是在表單執行查詢之后,組合框的值會像這樣混亂:

在 VBA 中重新查詢組合框并沒有改變任何東西。
我希望你能幫助我解決這個問題,因為我已經好幾天沒能解決這個問題了。
親切的問候
尼克·托馬斯
uj5u.com熱心網友回復:
這可以更簡單地完成:
Private Sub Form_Load()
Const RowSource As String = _
"Select ID, MonthText From ReportingDays " & _
"Where DateDiff('m', Date(), ReportingDay) Between -2 And 10"
Me!ReportingMonth.RowSource = RowSource
End Sub
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/488986.html
