向各位前辈请教一下:
我在ACCESS中创建了一个表kehu,里面就两个字段:company_name和beizhu
在VB中建了一个窗体frmEmpInfo2用来查询客户信息,我用的是模糊查询,想通过模糊查询company_name,把ACCESS中的beizhu信息返回到datagrid中,但是我的程序运行后就是不在datagrid中显示,而是另跳出一个提示框显示备注信息,请高手们指教一下。谢谢!
Option Explicit
Dim strsql As String
Dim rs As New ADODB.Recordset
Dim objscore As Recordset '保存客户信息
Dim conn As Recordset
Dim objcn As Connection '建立和保存数据库联接
Dim i As Integer
==========================================================
'清除
Private Sub cmdClear_Click()
Unload Me
End Sub
===============================================
'打印
Private Sub cmdPrint_Click()
If objscore.RecordCount < 1 Then Exit Sub
With objscore
.MoveFirst
strMsg = "" & objscore.Fields("备注")
End With
frmPrint.Show
frmPrint.Caption = "打印客户信息"
frmPrint.Print
frmPrint.Print
frmPrint.Print
frmPrint.Print strMsg
End Sub
=============================================
'查询
Private Sub Command1_Click()
Dim Link As New ADODB.Connection
Dim rs As New ADODB.Recordset
Link.CursorLocation = adUseClient
Link.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=ACCESS\kehu.mdb;Persist Security Info=False"
Link.Open
rs.Open "Select * From kehu Where company_name like '%" & txtCompany.Text & "%'", Link, adOpenDynamic, adLockOptimistic
If rs.RecordCount > 0 Then
'填写数据
MsgBox rs.Fields("beizhu").Value
Else
MsgBox "没有这个记录!"
End If
End Sub
========================
Private Sub Form_Load()
Dim DTbase As String
DTbase = App.Path + "\access\kehu.mdb"
Set objcn = New Connection
With objcn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.CursorLocation = adUseClient
.Open DTbase
End With
'建立数据库联接
Set conn = New Recordset
With conn
Set .ActiveConnection = objcn
.CursorLocation = adUseClient
.CursorLocation = adUseClient
.LockType = adLockOptimistic
'获取客户备注信息
End With
Set flexshow.DataSource = objscore
'设置列数
flexshow.Cols = 1
'列标题
flexshow.TextMatrix(0, 0) = "备注"
'设置列宽
flexshow.ColWidth(0) = 2000
End Sub