listbox 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
 
M

Malcolm Cook

Jason,

Is this for an adp project?

Do you need to pass parameters to your .source function?

Is it really a function (i.e. a table valued user defined function)?

Did you know that you can set the recordset of a combobox and listbox?

This may interest you

Private Sub Form_Load()
With Me.cboTestThis
.RowSource = "Table/View/StoredProc"
Set .Recordset = Access.CurrentProject.AccessConnection.Execute("select *
from dbo.my_UDF()")
End With
End Sub



Or, you can instead write:

.RowSourceType = "Value List"
.RowSource = Access.CurrentProject.AccessConnection.Execute("select *
from dbo.dbo.my_UDF()").GetString(, , ";", ";")
 

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