mauek unak
mauek unak

Reputation: 772

select [combobox value] & "text"

I am trying to build SELECT statement in Access VBA, based on value chosen by user in ComboBox.

Example :

"SELECT [8_SV_RT] FROM DATA WHERE condition = value

I need 8 to be dependent on ComboBox value from form. (8,10,12 ....)

The name of ComboBox is DN, and I created string COL = "_SV_RT"

So far I have :

"SELECT [DN] & '" & COL & "' FROM DATA WHERE condition = value

It returns value 8_SV_RT to ComboBox, which I want to use after SELECT statement, but not as result. I must be missing some syntax or something? Can anyone please advise?

Upvotes: 1

Views: 989

Answers (1)

Christian Specht
Christian Specht

Reputation: 36431

If I understand your question right:

Dim SQL As String

SQL = "SELECT [" & Me.MyComboBox & "_SV_RT] FROM DATA WHERE condition = value"

EDIT:
To use the exact object names from the question (before Siddharth edited it, I over-read that the combobox is named DN) and to take Siddharth's (now deleted) comment into consideration:

Dim SQL As String
Dim COL As String

COL = "_SV_RT"
SQL = "SELECT [" & DN & COL & "] FROM DATA WHERE condition = value"

Upvotes: 2

Related Questions