程序代码:
'cn连接数据库语句略 SQL1 = "Select * Fron UserInfo Where Username<>"" And LogUser<>""" RS.Open SQL1,cn,2,2 DO While Not RS.EOF Combo1.AddItem RS("Username") RS.MoveNext Loop RS.Close cn.Close
Private Sub Form_Load() ' Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\UIuser.mdb;Mode=ReadWrite|Share Deny None;Persist Security Info=False" Dim Scnn As Object, Srt As Object, use As String use = VBA.Environ("username") Combo1.Text = "" Set Scnn = New ADODB.Connection Scnn.CursorLocation = adUseClient Scnn.Open "Provider=Microsoft.jet.oledb.4.0;Data source=" & App.Path & "\UIuser.mdb" Set Srt = New ADODB.Recordset Set Srt.ActiveConnection = Scnn Srt.Open "select * from UserInfo" Do Until Srt.EOF Combo1.AddItem Srt.Fields("Username").Value Srt.MoveNext Loop Srt.Close 'cn连接数据库语句略 SQL1 = "Select * Fron UserInfo Where Username<>"" And LogUser<>""" Srt.Open SQL1, Scnn, 2, 2 Do While Not Srt.EOF Combo1.AddItem Srt("Username") Srt.MoveNext Loop Srt.Close Scnn.Close ' Srt.Close ' Set Srt = Nothing End Sub
[此贴子已经被作者于2017-8-24 13:09编辑过]
Dim Scnn As New ADODB.Connection, Srt As New ADODB.Recordset 'ADO对象声明 Combo1.Clear Combo1.Text = "" Scnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\UIuser.mdb;Persist Security Info=False" SQL1 = "Select * From UserInfo Where Username<>'' And LogUser<>''" 'From 错误打成了 Fron Srt.Open SQL1, Scnn, 2, 2 Do While Not Srt.EOF Combo1.AddItem Srt("Username") Srt.MoveNext Loop Srt.Close Scnn.Close