我有這個函數,我得到3075運行時錯誤。正是在這一行代碼中,我會在之後發佈。 我有一個子表單,有3個框可以選擇任何選項以獲取表單上的數據(品牌,通用,製造商)。我認爲使用IF語句獲取數據以形成問題有些問題,但不知道如何重新編寫它。訪問運行時錯誤3075
錯誤線是這在調試模式下 - Me.tbl_Drug_Master_Date_subform.Form.RecordSource =任務
錯誤消息指出:在查詢表達式語法錯誤(缺少運營商)'[Brand]=Idaloprine'And[Generic] like '*'And[Manufacturer] like '*'
全碼:
Function SearchCriteria()
Dim Brandtype, strGeneric, strManufacturer
Dim task, strCriteria As String
If IsNull(Me.cboBrand) Then
Brandtype = "[BRAND] like '*'"
Else
Brandtype = "[BRAND] = " & Me.cboBrand & "'"
End If
If IsNull(Me.cboGeneric) Then
strGeneric = "[Generic] like '*'"
Else
strGeneric = "[Generic] = " & Me.cboGeneric & "'"
End If
If IsNull(Me.cboManufacturer) Then
strManufacturer = "[MANUFACTURER] like '*'"
Else
strManufacturer = "[MANUFACTURER] = " & Me.cboManufacturer & "'"
End If
strCriteria = Brandtype & "And" & strGeneric & "And" & strManufacturer
task = "Select GENERIC, BRAND, MASTER_ID, PRODUCT_CATEGORY, MANUFACTURER, HTP_MODEL_QTR, HTP_SELECTION_REASON1, LU.ID, LU.Date_YYYYQX from [tbl_Drug_Master] DM left outer join tbl_YYYYQX_LU LU on LU.ID = DM.HTP_MODEL_QTR Where " & strCriteria
Me.tbl_Drug_Master_Date_subform.Form.RecordSource = task
Me.tbl_Drug_Master_Date_subform.Form.Requery
End Function
確保當您發佈的代碼檢查格式和縮進在預覽,這樣的代碼格式正確,具有可讀壓痕(你的格式不正確)。 – crashmstr