Solved how to listbox for specific record (1 Viewer)

MK1999

New member
Local time
Today, 02:50
Joined
Mar 30, 2022
Messages
24
hi,
i want to view all programs for a coordinator to appear in a listbox with other information such as year..

i wrote this command

Dim stringCo as string
StringCo = "SELECT [CoordinatorID],[year],[nameÌ],[Co_name]" & "FROM Qco" & _
"WHERE [CoordinatorID] = Me.CoordinatorID.Text"
CoPro.RowSource = StringCo

it works fine for all records but when i run the condition (
& _
"WHERE [CoordinatorID] = Me.CoordinatorID.Text")
it gives a blank list box

any ideas?
 

bob fitz

AWF VIP
Local time
Today, 00:50
Joined
May 23, 2011
Messages
4,719
Perhaps
"WHERE [CoordinatorID] =" & Me.CoordinatorID)
If CoordinatorID is text rather than number, try
"WHERE [CoordinatorID] ='" & Me.CoordinatorID & "'")
 

MK1999

New member
Local time
Today, 02:50
Joined
Mar 30, 2022
Messages
24
thankyou but didnt work.. same issue blank listbox
 

bob fitz

AWF VIP
Local time
Today, 00:50
Joined
May 23, 2011
Messages
4,719
What is Me.CoordinatorID
Is the listbox bound
 

moke123

AWF VIP
Local time
Yesterday, 19:50
Joined
Jan 11, 2013
Messages
3,912
Code:
StringCo = "SELECT [CoordinatorID],[year],[nameÌ],[Co_name]" & "FROM Qco" & _
"WHERE [CoordinatorID] = Me.CoordinatorID.Text"

Year and Name are reserved words so you should change those to something like dteYear and txtName.
When you concatenate strings make sure you account for spaces between words.
Code:
"FROM Qco" & _ 
"WHERE
will read as
Code:
"FROM QcoWHERE
you need to add a space after Qco or before Where.

if CoordinatorID is text datatype
"WHERE CoordinatorID = """ & Me.CoordinatorID & """"

if CoordinatorID is numeric datatype
"WHERE CoordinatorID = " & Me.CoordinatorID
 

GPGeorge

Grover Park George
Local time
Yesterday, 16:50
Joined
Nov 25, 2004
Messages
1,829
hi,
i want to view all programs for a coordinator to appear in a listbox with other information such as year..

i wrote this command

Dim stringCo as string
StringCo = "SELECT [CoordinatorID],[year],[nameÌ],[Co_name]" & "FROM Qco" & _
"WHERE [CoordinatorID] = Me.CoordinatorID.Text"
CoPro.RowSource = StringCo

it works fine for all records but when i run the condition (
& _
"WHERE [CoordinatorID] = Me.CoordinatorID.Text")
it gives a blank list box

any ideas?
The code as posted can't work. You are concatenating strings with NO spaces between words. E.g. ... [Co_name]" & "From Qco" & _
That same thing occurs in the beginning of the next line.

The result is a string that CAN'T return anything because it's not valid SQL.

You are creating a string variable called "StringCo". Use Debug.Print to show it in the Immediate Window. Copy it to a new query and see what error is raised. Then you'll know how to fix it.
 

GPGeorge

Grover Park George
Local time
Yesterday, 16:50
Joined
Nov 25, 2004
Messages
1,829
The code as posted can't work. You are concatenating strings with NO spaces between words. E.g. ... [Co_name]" & "From Qco" & _
That same thing occurs in the beginning of the next line.

The result is a string that CAN'T return anything because it's not valid SQL.

You are creating a string variable called "StringCo". Use Debug.Print to show it in the Immediate Window. Copy it to a new query and see what error is raised. Then you'll know how to fix it.
Ah, I see Moke123 already pointed out the space problem....
 

moke123

AWF VIP
Local time
Yesterday, 19:50
Joined
Jan 11, 2013
Messages
3,912
Ah, I see Moke123 already pointed out the space problem....
But I forgot to mention debug.print which probably would have shown him the error before he even needed to post.
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 19:50
Joined
Feb 19, 2002
Messages
43,233
And then there's the confusion caused by using table level lookups. Do you have one of those by chance? If so, the combo will be returning the ID not the name of the company.
 

Users who are viewing this thread

Top Bottom