hhg4 发表于 2005-5-11 16:04:00

[求助]

<FONT color=#cc3370><FONT face=黑体 size=2>请教斑竹;</FONT></FONT>


以下是我用VB调用ACCESS数据库的一段程序,前面一段是关于登录窗体的,后面是主窗体.在ACCESS中插入了AUTOCAD对象,数据库保存在Template子目录下.与ACCESS的连结通过数据窗体向导实现,许多代码是自动生成.程序调试时提示:数据库路径为不合法路径.且在登陆窗体上输入用户名和密码后提示:密码错误!请斑竹帮忙看一下程序有哪些错误以及还有哪些需要改进的地方.


下面是登录窗体程序:


Private Sub cmdCancel_Click()<BR>Unload Me<BR>End Sub


Private Sub cmdOK_Click()<BR>        On Error Resume Next<BR>                       Dim sqlstr As String<BR>                       sqlstr = "select * from 用户表 where 用户名 = '" &amp; Trim(txtUserName.Text) &amp; "'and 密码 = '" &amp; Trim(txtPassword.Text) &amp; "'"<BR>                       Me.Data1.RecordSource = sqlstr<BR>                       Me.Data1.Refresh<BR>                       If Me.Data1.Recordset.RecordCount = 0 Then<BR>                                                       MsgBox "密码错误!"<BR>                       Else<BR>                                                       frmMain.Show<BR>                                                       Unload Me<BR>                       End If<BR>End Sub


Private Sub Form_Load()<BR>                       Me.Data1.DatabaseName = App.Path &amp; "\ Template \ 产品图档管理系统97.mdb"<BR>End Sub


以下是主窗体程序:


<BR>Private Sub Command1_Click()<BR>                       Dim str As String<BR>                       If Combol.Text = " " Or Text1.Text = " " Then<BR>                                                       MsgBox "请输入查询条件和内容!"<BR>                                                       Exit Sub<BR>                       End If<BR>                       str = Combol.Text &amp; "like" &amp; "'" &amp; Text1.Text &amp; "'"<BR>                       datPrimaryRS.Recordset.Find str<BR>                       If datPrimaryRS.Recordset.AbsolutePosition &lt; adPosBOF Then<BR>                                                       MsgBox "没有相应的记录!"<BR>                                                       datPrimaryRS.Recordset.MoveFirst<BR>                                                       <BR>                       End If<BR>End Sub


Private Sub Form_Load()<BR>Me.datPrimaryRS.ConnectionString = "PROVIDER = Microsoft.Jet.OLEDB.3.51;datasource=" &amp; App.Path &amp; " \template\产品图档管理系统97.mdb;"<BR>Me.datPrimaryRS.RecordSource = "select 备注说明,编号,产品材料,产品名称,产品数量,产品图号,产品图形,绘图比例,绘图人,绘图日期,设计单位,设计人,设计日期,设计文档,审阅人,审阅日期,图形文件名 from 产品图档 Order by 产品图号"<BR>Me.datPrimaryRS.Refresh<BR>End Sub


Private Sub Form_Unload(Cancel As Integer)<BR>       Screen.MousePointer = vbDefault<BR>End Sub


Private Sub datPrimaryRS_Error(ByVal ErrorNumber As Long, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, fCancelDisplay As Boolean)<BR>       'This is where you would put error handling code<BR>       'If you want to ignore errors, comment out the next line<BR>       'If you want to trap them, add code here to handle them<BR>       MsgBox "Data error event hit err:" &amp; Description<BR>End Sub


Private Sub datPrimaryRS_MoveComplete(ByVal adReason As ADODB.EventReasonEnum, ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)<BR>       'This will display the current record position for this recordset<BR>       datPrimaryRS.Caption = "Record: " &amp; CStr(datPrimaryRS.Recordset.AbsolutePosition)<BR>End Sub


Private Sub datPrimaryRS_WillChangeRecord(ByVal adReason As ADODB.EventReasonEnum, ByVal cRecords As Long, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)<BR>       'This is where you put validation code<BR>       'This event gets called when the following actions occur<BR>       Dim bCancel As Boolean


       Select Case adReason<BR>       Case adRsnAddNew<BR>       Case adRsnClose<BR>       Case adRsnDelete<BR>       Case adRsnFirstChange<BR>       Case adRsnMove<BR>       Case adRsnRequery<BR>       Case adRsnResynch<BR>       Case adRsnUndoAddNew<BR>       Case adRsnUndoDelete<BR>       Case adRsnUndoUpdate<BR>       Case adRsnUpdate<BR>       End Select


       If bCancel Then adStatus = adStatusCancel<BR>End Sub


Private Sub cmdAdd_Click()<BR>       On Error GoTo AddErr<BR>       datPrimaryRS.Recordset.AddNew


       Exit Sub<BR>AddErr:<BR>       MsgBox Err.Description<BR>End Sub


Private Sub cmdDelete_Click()<BR>       On Error GoTo DeleteErr<BR>       With datPrimaryRS.Recordset<BR>                       .Delete<BR>                       .MoveNext<BR>                       If .EOF Then .MoveLast<BR>       End With<BR>       Exit Sub<BR>DeleteErr:<BR>       MsgBox Err.Description<BR>End Sub


Private Sub cmdUpdate_Click()<BR>       On Error GoTo UpdateErr


       datPrimaryRS.Recordset.UpdateBatch adAffectAll<BR>       Exit Sub<BR>UpdateErr:<BR>       MsgBox Err.Description<BR>End Sub


Private Sub cmdClose_Click()<BR>       Unload Me<BR>End Sub
页: [1]
查看完整版本: [求助]