how assign vba query to listbox

sohailcdc

Registered User.
Local time
Today, 08:13
Joined
Sep 25, 2012
Messages
55
Hello there
I am total green in access specially in VBA world and trying to learn during my free time

I am able to learn to learn how to assign values to LISTBOX, based on already created Query (using Wizard)

Now I am trying to learn, HOW to create the query through VBA and assign to listbox instead of first creating query

What exactly I am trying to learn is upon opening of the my listbox show already existed records (for information)

Thanks in advance for your kind help

Following the information
tlb name = Currency
tlbfield1=Currencycode
tlbfield2=Currencyname

Private Sub Form_Load()
Dim sql1 As Integer
sql1 = SELECT Currency.[Currencycode] AS Code, Currency.[Currencyname] AS Name FROM [Currency];
DoCmd.RunSQL sql1
Me.listcurcode.RowSource = sql1
Me.listcurcode.Requery
End Sub
 
You're close. Try

Dim sql1 As String
sql1 = "SELECT Currency.[Currencycode] AS Code, Currency.[Currencyname] AS Name FROM [Currency]"

Me.listcurcode.RowSource = sql1
 
sohailcdc,

You've got it already!
Just take your sql1 string and put it into the Row Source property of your ListBox:
Code:
SELECT Currency.[Currencycode] AS Code, Currency.[Currencyname] AS Name FROM [Currency];

_________________
Regards,
Marvin M :cool:
Windows 7 Professional, MS Access 2007/2010
Windows 8 Professional, MS Access 2013
-------------------------------------------------------------------------------------------------------------------
If my post has helped you, please click the scales or click the 'Thumbs up'. Thanks!
-------------------------------------------------------------------------------------------------------------------
 
Oh, I see what you mean. Paul is right.
I always put a semicolon at the end of that SQL statement. Does it work without it?
 
Thank you, it works perfectly Yahoo! I learn something today
 
Happy to help!

Marvin, the semicolon is optional. I never put them in.
 

Users who are viewing this thread

Back
Top Bottom