Using variable and controls in sql strings (1 Viewer)

Lol999

Registered User.
Local time
, 21:54
Joined
May 28, 2017
Messages
184
Hi, could someone point me in the direction of some resource for the proper syntax of including, say, the output from a combobox into an sql string in vba?

Many thanks, Lol
 

1268

Registered User.
Local time
, 23:54
Joined
Oct 11, 2012
Messages
44
Hi, could someone point me in the direction of some resource for the proper syntax of including, say, the output from a combobox into an sql string in vba?

Many thanks, Lol
Variable = me.combox if within the form. You have to reference the form if not. Google it, pretty basic, tons of info out their already.

Sent from my SM-G950U using Tapatalk
 

sonic8

AWF VIP
Local time
Today, 06:54
Joined
Oct 27, 2015
Messages
1,001
Hi, could someone point me in the direction of some resource for the proper syntax of including, say, the output from a combobox into an sql string in vba?
First, a ComboBox has no "output". It has properties that you can use in SQL queries based on the selection in the ComboBox. Most of the time, you want to use the Value property, which contains the value of the first column of the selected record of the Rowsource. Sometimes you rather need the value of another column. You can access that with the indexed Column property.

Building a SQL string with the numeric value of a ComboBox in the form of the control would look like this in code:
Code:
strSQL = "SELECT SomeColumns FROM yourTable WHERE aColumn= " & Me.yourComboBox.Value
Please see my extensive tutorial on SQL strings building in VBA for further reference.
The link to MSDN, provided by Beetle, is quite good as well, but it lacks essential information for Non-US environments.
 

Users who are viewing this thread

Top Bottom