带有vba代码的访问表单,会为adodb连接生成错误 [英] access form with vba code generating error for adodb connection
问题描述
我的vba访问代码无法正常工作,并且显示了某种运行时错误.请帮帮我
这是代码
在错误代码行中,它指出没有给其他必需的参数值
my vba code for access is not working and it is showing some kind of runtime error. please help me out
here is the code
in block is the error line it says that one more required parameters are not given values
Private Sub Command7_Click()
Dim err As Boolean
Dim con1 As ADODB.Connection
Dim recSet1 As ADODB.Recordset
Dim strSQL As String
'check that the user enter something
txtuName.SetFocus
If txtuName.Text = "" Then
MsgBox "Please enter all required information."
err = True
End If
'check that the user entered valid data i.e non-numerical
txtuPass.SetFocus
If txtuPass.Text = "" Then
MsgBox "Enter password"
err = True
End If
If IsNumeric(txtuPass) Then
MsgBox "Invalid format"
txtuPass.SetFocus
err = True
End If
txtuPass.SetFocus
If Len(txtuPass) > 10 Then
MsgBox "Please check your password and try again"
err = True
End If
'run sql query to verify that the user exist
txtuName.SetFocus
If Not err Then
SQL = "SELECT uName, uPass FROM users WHERE uName=" & txtuName.Text
Set con1 = CurrentProject.Connection
Set recSet1 = New ADODB.Recordset
recSet1.Open SQL, con1
If recset.RecordCount > 10 Then
'user does exist in database
MsgBox "You can access the application"
Else
'user does not exist
MsgBox "Your login details do not match"
End If 'recordcount
recset.Close
con.Close
Set con = Nothing
Set recset = Nothing
End If
End Sub
推荐答案
好,我看到2个问题:
1)SQL变量.
OK, i see 2 problems:
1) SQL variable.
SQL = "SELECT uName, uPass FROM users WHERE uName=""" & txtuName.Text & """"
或
or
SQL = "SELECT uName, uPass FROM users WHERE uName=''" & txtuName.Text & "''"
阅读有关以下内容的更多信息:编写查询T-SQL(google).
2)正如我之前写的recordset.Open
方法有很多参数.检查 http://msdn上的CursorType
和LockType
参数. microsoft.com/en-us/library/ms675544%28v=vs.85%29.aspx [
Read more about: writing queries T-SQL (google).
2) As i wrote before recordset.Open
method has many parameters. Check CursorType
and LockType
parameters on http://msdn.microsoft.com/en-us/library/ms675544%28v=vs.85%29.aspx[^] and set it properly.
这篇关于带有vba代码的访问表单,会为adodb连接生成错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!