1
Private Sub cmdAdd_Click()
'add data to table
CurrentDb.Execute = "INSERT INTO jscbb_dir2(ID,Lastname,FirstName, PrimA, Artea,LubNum,OfficeNum,OfficePhone,Email,LabPhone,stats)" & _
" VALUES(" & Me.Textid & ",'" & Me.TextLast & "','" & Me.TextFirst & "','" & Me.Textprima & "','" & Me.Textarea & "','" & Me.Textlabnum & _
"','" & Me.Textofficenum & "','" & Me.Textofficephone & "','" & Me.Textemail & "','" & Me.Textlabphone & "','" & Me.Textstatus & "')"

'refresh data is list on focus
jscbb_dirsub.Form.Requery

End Sub

为什么我在最后一个 (Me.Textstatus) 上出现错误?我知道这是一个低级的问题,但我需要另一双眼睛,我已经看了一个多小时了。错误是“编译错误:参数不是可选的”

4

2 回答 2

1

考虑参数,它们会更容易调试。

Dim qdf As QueryDef
ssql = "INSERT INTO jscbb_dir2(ID,Lastname,FirstName,PrimA,Artea," _
     & "LubNum,OfficeNum,OfficePhone,Email,LabPhone,stats) " _
     & "VALUES([id],[last],[first],[prima],[area],[lab]," _
     & "[office],[phone],[email],[stat])"
Set qdf = CurrentDb.CreateQueryDef("", ssql)
qdf.Parameters("id") = Me.TextID
qdf.Parameters("last") = Me.Textlast
qdf.Parameters("first") = Me.Textfirst
qdf.Parameters("prima") = Me.Textprima
qdf.Parameters("area") = Me.Textarea
qdf.Parameters("lab") = Me.Textlabnum
qdf.Parameters("office") = Me.Textofficenumbet
qdf.Parameters("phone") = Me.Textofficephone
qdf.Parameters("email") = Me.Textemail
qdf.Parameters("stat") = Me.Textstatus

qdf.Execute dbFailOnError
于 2013-03-21T20:53:59.720 回答
0

Execute是一种方法,而不是一种属性。您不要=在方法及其参数之间使用,所以

CurrentDb.Execute = "..."

应该

CurrentDb.Execute "..."
于 2014-07-20T18:15:02.030 回答