Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Vb code on entering values.

Status
Not open for further replies.

TheunsGoosen

Technical User
Jan 17, 2007
36
GB
(Access beginner)
I have a query that is displaying a answer in form view as a guide line, if the user is happy with the answer he can press the command button so to allow the query values to display in the combo box for further use or type in his own vallues, but im strugglig with the vb code?

Private Sub Command331_Click()

?

End Sub

Thanks
TC
 
eh? is your question: "how do I dynamically populate the options in a combo box from a query?"?

if it is then you have 2 options.
if your using a dynamic query then you need to use a recordset like so:

Code:
Dim MyRS As ADODB.Recordset
Dim Conn As ADODB.Connection
Dim MyQuery As String

MyQuery = "select CustomerName from Customers"


Set Conn = Application.CurrentProject.Connection
Conn.Open
Set MyRS = New ADODB.Recordset

MyRS.Open MyQuery, Conn

Do While Not MyRS.EOF
    MyCombo.AddItem MyRS.Fields("CustomerName")
    MyRS.MoveNext
Loop

MyRS.Close
Set MyRS = Nothing

Conn.Close
Set Conn = Nothing

or if your query is static and saved as an Access query then simply do this:

Code:
MyCombo.RecordSource = "Query1"
MyCombo.Requery

Cheers

Nick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top