call function

J

Jason

Hi,

Could somebody help me make the following code to be used as a function? I
want to call it in every form where i have listboxes or comboboxes. The
source of the recordset should also come from a function.

Public Function Filler()

Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim strValueList As String

Set cnn = GetConnection(True)

Set rst = New ADODB.Recordset

With rst
.ActiveConnection = cnn
.Source = <function?>
.Open
Do Until .EOF
strValueList = strValueList & rst.Fields("field1") & ";" & _
rst.Fields("field2") & ";"
.MoveNext
Loop
End With

With lstcmb
.RowSourceType = "Value List"
.RowSource = strValueList
End With

rst.Close

Set rst = Nothing

cnn.Close

Set cnn = Nothing

End Function
 
T

Tim Ferguson

The
source of the recordset should also come from a function.

Put the query into a string variable and pass it as an argument to the
Filler() function.

But it seems a very expensive way of duplicating what Access does anyway...

B Wishes


Tim F
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top