Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Shawn Lopez   on Jan 28 In MS Office Category.

  
Question Answered By: Ethan Evans   on Jan 28

I do not know which control you are using however, you will probably either set
the control source to the recordset  or, as I would do, loop through the
recordset and use additem to add the row to the control. See code below for an
example. Please post again to let me know if it works or not. this code adds
values to a combo box.

Private Function cboAnalysisLoad(cboDatabase As String)
Dim strParam As String

ConnectDB

Set objSourceRS = New ADODB.Recordset

With objSourceRS
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = adLockBatchOptimistic
.ActiveConnection = objConn
End With

gstrSQL = "SELECT Name, Description, Rundate, ID FROM " & cboDatabase &
".dbo.RDM_ANALYSIS RDM_ANALYSIS WHERE EXPOSURETYPE in (8017,8029) ORDER BY Name,
Rundate"

objSourceRS.Open gstrSQL
With cboAnalysis
.Clear

Do While Not objSourceRS.EOF
.AddItem objSourceRS.Fields("Name").Value
.List(0, 1) = objSourceRS.Fields("Description").Value
.List(0, 2) = objSourceRS.Fields("Rundate").Value
.List(0, 3) = objSourceRS.Fields("ID").Value
objSourceRS.MoveNext
Loop

End With


objSourceRS.Close
End Function

Share: 

 

This Question has 2 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Help needed in SQL to Excel VBA Form Or get search suggestion and latest updates.


Tagged: