visual basic code:
Private Sub Populate_City_Search() Dim sStr As String Dim adoRec As ADODB.Recordset sStr = "SELECT * FROM City" Set adoRec = mRecordSet(sStr) Do Until adoRec.EOF cboSearchCity.AddItem adoRec!city adoRec.MoveNext Loop Set adoRec = Nothing End Sub Function: Public Function mRecordSet(sSql As String) As ADODB.Recordset Dim adoConnection As ADODB.Connection Dim adoRecSet As ADODB.Recordset Dim connectString As String ' Create new connection Set adoConnection = New ADODB.Connection ' Build connection string connectString = "Provider=Microsoft.Jet.OLEDB.4.0;" _ & "Data Source=" & App.Path & "\data.mdb" adoConnection.Open connectString Set adoRecSet = adoConnection.Execute(sSql) Set mRecordSet = adoRecSet 'adoRecSet.Close 'adoConnection.Close Set adoRecSet = Nothing Set adoConnection = Nothing End Function
Wokawidget
Naughty Sniffing Shark
Registered: Nov 01
Location: Baghdad, Iraq Occupation: Classified
Posts: 5686Similar to what I use...
I have modified you code slightly...Hope this helps.
visual basic code:
Option Explicit Private Sub Populate_City_Search() Dim strSQL As String Dim adoRec As ADODB.Recordset Screen.MousePointer = vbHourglass cboSearchCity.Clear strSQL = "SELECT * " strSQL = strSQL & "FROM City " Set adoRec = OpenRecordset(strSQL) With adoRec Do While Not .EOF cboSearchCity.AddItem .Fields("city").Value .MoveNext Loop End With Set adoRec = Nothing Screen.MousePointer = vbDefault End Sub Public Function OpenRecordset(ByRef pstrSQL As String) As ADODB.Recordset Dim adoRec As ADODB.Recordset Dim strConn As String strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & App.Path & "\data.mdb" Set adoRec = New Recordset With adoRec .CursorLocation = adUseClient .Open pstrSQL, strConn, adOpenForwardOnly, adLockReadOnly Set .ActiveConnection = Nothing End With Set OpenRecordset = adoRec Set adoRec = Nothing End Function
Adios,
Woka
__________________
Taliban strategy of hiding "not fair and probably illegal" says US military...
How to multi thread in VB 6
Warning: Do NOT download and run any compiled code that users post on VBF asking you to test. Always ask for the source code.04-29-2003 02:49 PM