收到错误3075:链接到文本框的组合框的语法错误

时间:2017-11-07 18:13:58

标签: vba ms-access

每当我尝试运行表单时,我都会收到此错误,

screenshot of form

错误:

error

这样做的想法是选择一个字段,输入文本并让它根据文本输入拉出记录,如果没有匹配则会说“没有找到记录”。仍然是VBA新手,任何帮助将不胜感激。代码如下。 cboField 是组合框, txtBox 是文本框。我正在运行Access 2010以供参考。

LinkedList foo = myList.get(index);
int bar = foo.get(newIndex);

2 个答案:

答案 0 :(得分:0)

...避免在评论中回答问题。

反正。在VBA中构建SQL字符串时,Debug.Print和密切读取输出是您的朋友。 How to debug dynamic SQL in VBA

Debug.Print sfilter
FirstNameLIKE 'joe *'

注意缺失和多余的空间,制作

sfilter = cboField & " LIKE '" & txtBox & "*'"

答案 1 :(得分:0)

现在正在运行,感谢所有人的帮助,我已经发布了包含编辑内容的来源。

Option Compare Database

Private Sub cboField_Enter()
Dim oRS As DAO.Recordset, i As Integer
If Me.Form.FilterOn = True Then DoCmd.ShowAllRecords
Set oRS = Me.RecordsetClone
cboField.RowSourceType = "Value List"
cboField.RowSource = ""

For i = 0 To oRS.Fields.Count - 1
If oRS.Fields(i).Type = dbText Then cboField.AddItem oRS.Fields(i).Name
 Next i

 End Sub

 Private Sub txtBox_Exit(Cancel As Integer)
 Dim sfilter As String, oRS As DAO.Recordset
 If IsNull(cboField) Then
 DoCmd.ShowAllRecords
 MsgBox "select a field"
 Exit Sub
 End If
 If IsNull(txtBox) Then DoCmd.ShowAllRecords: Exit Sub
 sfilter = cboField & " LIKE '" & txtBox & "*'"
 DoCmd.ApplyFilter , sfilter
 Debug.Print sfilter


 Set oRS = Me.RecordsetClone
 If oRS.RecordCount = 0 Then
 MsgBox " no record matches"
 DoCmd.ShowAllRecords
 End If

 End Sub