我正在尝试检索保存在MS Access数据库中的记录,并在FORM_LOAD()
期间使用查询结果填充文本框。到目前为止,我检索了一条记录但问题是,当我尝试添加相同的代码时,它会检索第一个保存的记录。
无视我的sql语句中的where子句。这就是我想要的输出。在form_load()
期间,我想在我的表单上的多个文本框中显示多个记录(活动描述/ activity_desc)。如果我的数据库中没有记录,我只想让它为空白。
这是我想要实现的目标.. 这是我的代码段:
Private Sub Form_Load()
FrmSchedule.lblnamesched.Caption = FrmInfosheet.Txtname.Text
FrmSchedule.Label36.Caption = FrmInfosheet.cmbsalesgroup.Text
FrmSchedule.lblpositionsched = FrmInfosheet.Txtposition.Text
FrmSchedule.Thisweekdate.Caption = FrmInfosheet.Text3.Text
FrmSchedule.Thisweekdate2.Caption = FrmInfosheet.Text4.Text
FrmSchedule.Label37.Caption = FrmWeek1WAR.Label1.Caption
FrmSchedule.Label38.Caption = FrmWeek1WAR.Label2.Caption
FrmSchedule.Label39.Caption = FrmWeek1WAR.Label21.Caption
FrmSchedule.Label40.Caption = FrmWeek1WAR.Label22.Caption
FrmSchedule.Label41.Caption = FrmWeek1WAR.Label23.Caption
FrmSchedule.Label42.Caption = FrmWeek1WAR.Label37.Caption
FrmSchedule.Label43.Caption = FrmWeek1WAR.Label26.Caption
FrmSchedule.Label44.Caption = FrmWeek1WAR.Label27.Caption
FrmSchedule.Label45.Caption = FrmWeek1WAR.Label28.Caption
FrmSchedule.Label46.Caption = FrmWeek1WAR.Label29.Caption
FrmSchedule.Label47.Caption = FrmWeek1WAR.Label30.Caption
FrmSchedule.Label48.Caption = FrmWeek1WAR.Label38.Caption
Dim conConnection As ADODB.Connection
Dim rs As ADODB.Recordset
Dim sqlStr As String
Dim clone_rs As ADODB.Recordset
Set conConnection = New ADODB.Connection
Set rs = New ADODB.Recordset
With conConnection
.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
App.Path & "\" & "WAP.mdb;Mode=Read|Write"
.Open
End With
With rs
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = adLockBatchOptimistic
.ActiveConnection = conConnection
.Open "war", conConnection, adOpenForwardOnly
End With
'Set clone_rs = rs.Clone
With arsProjects
If rs.BOF And rs.EOF Then
.Requery
.MoveFirst
.MoveLast
Else
sqlStr = "SELECT activity_desc FROM war WHERE time = '8' and activity_date = '" & Label37.Caption & "' and sales_group = 'ALC Holdings CO., INC' and day = 'Monday'"
Text1.Text = rs.Fields("activity_desc")
sqlStr = "SELECT activity_desc FROM war WHERE time = '9' and activity_date = '" & Label38.Caption & "' and sales_group = 'ALC Holdings CO., INC' and day = 'Tuesday'"
Text2.Text = rs.Fields("activity_desc")
End If
End With
Set rs = Nothing
Set conConnection = Nothing
End Sub
如果我做错了,那么实现我想要的东西的正确功能或代码是什么。任何帮助和建议将不胜感激。通过这种方式,我试图使用多个选择查询来实现这一目标。
答案 0 :(得分:0)
您将SELECT语句分配给sqlStr但它看起来不像您在任何地方使用sqlStr。在rs.Open中你有一个选择语句“war”而不是sqlStr。