VBA Quotes using IIF

S

scott

In CODE 1 below, I have a working SELECT statement that is the RowSource for
a combo box named cbotrackID. I'm trying to write it out in VBA, but I'm
having a lot of trouble with the quotes. I didn't put my failed code in CODE
2 because I didn't want to confuse anyone.

Can someone help me convert the SQL in CODE 1 into a VBA statement that I
can use in VBA to set the RowSource with a code version of the sql?


CODE 1 **********

SELECT t.trackID, t.trackNum, [trackNum] & ") " & [trackSong] &
IIf(IsNull([trackTime]),""," (" & [trackTime] & ")") AS Song,

t.trackSong, t.trackTime

FROM t_track t



CODE 2 **********

Me.cbotrackID.RowSource = ???
 
K

Ken Snell \(MVP\)

Dim strSQL As String
strSQL = "SELECT t.trackID, t.trackNum, [trackNum] & ") " & _
[trackSong] & IIf(IsNull([trackTime]),""," (" & [trackTime] & ")") _
& "AS Song, t.trackSong, t.trackTime FROM t_track t"
 
S

scott

I'm still getting an error. Can you try to print.debug your statement? Sorry
for delay, i had an emergency come up.


Ken Snell (MVP) said:
Dim strSQL As String
strSQL = "SELECT t.trackID, t.trackNum, [trackNum] & ") " & _
[trackSong] & IIf(IsNull([trackTime]),""," (" & [trackTime] & ")") _
& "AS Song, t.trackSong, t.trackTime FROM t_track t"

--

Ken Snell
<MS ACCESS MVP>



scott said:
In CODE 1 below, I have a working SELECT statement that is the RowSource
for a combo box named cbotrackID. I'm trying to write it out in VBA, but
I'm having a lot of trouble with the quotes. I didn't put my failed code
in CODE 2 because I didn't want to confuse anyone.

Can someone help me convert the SQL in CODE 1 into a VBA statement that I
can use in VBA to set the RowSource with a code version of the sql?


CODE 1 **********

SELECT t.trackID, t.trackNum, [trackNum] & ") " & [trackSong] &
IIf(IsNull([trackTime]),""," (" & [trackTime] & ")") AS Song,

t.trackSong, t.trackTime

FROM t_track t



CODE 2 **********

Me.cbotrackID.RowSource = ???
 
K

Ken Snell \(MVP\)

Sorry - try this:

Dim strSQL As String
strSQL = "SELECT t.trackID, t.trackNum, [trackNum] & ') '" & _
"[trackSong] & IIf(IsNull([trackTime]),'',' (' & [trackTime] & ')')" _
& "AS Song, t.trackSong, t.trackTime FROM t_track t"

--

Ken Snell
<MS ACCESS MVP>


scott said:
I'm still getting an error. Can you try to print.debug your statement?
Sorry for delay, i had an emergency come up.


Ken Snell (MVP) said:
Dim strSQL As String
strSQL = "SELECT t.trackID, t.trackNum, [trackNum] & ") " & _
[trackSong] & IIf(IsNull([trackTime]),""," (" & [trackTime] & ")") _
& "AS Song, t.trackSong, t.trackTime FROM t_track t"

--

Ken Snell
<MS ACCESS MVP>



scott said:
In CODE 1 below, I have a working SELECT statement that is the RowSource
for a combo box named cbotrackID. I'm trying to write it out in VBA, but
I'm having a lot of trouble with the quotes. I didn't put my failed code
in CODE 2 because I didn't want to confuse anyone.

Can someone help me convert the SQL in CODE 1 into a VBA statement that
I can use in VBA to set the RowSource with a code version of the sql?


CODE 1 **********

SELECT t.trackID, t.trackNum, [trackNum] & ") " & [trackSong] &
IIf(IsNull([trackTime]),""," (" & [trackTime] & ")") AS Song,

t.trackSong, t.trackTime

FROM t_track t



CODE 2 **********

Me.cbotrackID.RowSource = ???
 
S

scott

I had to modify it a bit, but it works. Thanks.


Ken Snell (MVP) said:
Sorry - try this:

Dim strSQL As String
strSQL = "SELECT t.trackID, t.trackNum, [trackNum] & ') '" & _
"[trackSong] & IIf(IsNull([trackTime]),'',' (' & [trackTime] & ')')" _
& "AS Song, t.trackSong, t.trackTime FROM t_track t"

--

Ken Snell
<MS ACCESS MVP>


scott said:
I'm still getting an error. Can you try to print.debug your statement?
Sorry for delay, i had an emergency come up.


Ken Snell (MVP) said:
Dim strSQL As String
strSQL = "SELECT t.trackID, t.trackNum, [trackNum] & ") " & _
[trackSong] & IIf(IsNull([trackTime]),""," (" & [trackTime] & ")") _
& "AS Song, t.trackSong, t.trackTime FROM t_track t"

--

Ken Snell
<MS ACCESS MVP>



In CODE 1 below, I have a working SELECT statement that is the
RowSource for a combo box named cbotrackID. I'm trying to write it out
in VBA, but I'm having a lot of trouble with the quotes. I didn't put
my failed code in CODE 2 because I didn't want to confuse anyone.

Can someone help me convert the SQL in CODE 1 into a VBA statement that
I can use in VBA to set the RowSource with a code version of the sql?


CODE 1 **********

SELECT t.trackID, t.trackNum, [trackNum] & ") " & [trackSong] &
IIf(IsNull([trackTime]),""," (" & [trackTime] & ")") AS Song,

t.trackSong, t.trackTime

FROM t_track t



CODE 2 **********

Me.cbotrackID.RowSource = ???
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top