Redisplaying selected in listbox

  • Thread starter spokane29 via AccessMonster.com
  • Start date
S

spokane29 via AccessMonster.com

I have a listbox that has the following SQL in a query:

SELECT tblResponsesList.Rspns, tblResponsesList.QstnID
FROM tblResponsesList
WHERE (((tblResponsesList.QstnID)=[Form]![QstnID]));


I want to have it if I return back to the record at some point, the listbox
will show all the options and have selected the selected choices that are
stored in tblResponses.

I have tried:

For x = 0 To ListRspns.ListCount - 1
If ListRspns.ItemData(x) = DLookup("Rspns", "tblResponses", "QstnID=" & Me!
QstnID) Then
ListRspns.Selected(x) = True
End If
Next x

However, for some reason this is not working. Thoughts? Could it be because
I have 2 columns in my listbox (Rspns and QstnID)?

The table structure is:
tblAssociates
--AssociateID
--Associate_Last_Name
--Associate_First_Name
--etc...

tblResponse
--AssociateRef (1-many with tblAssociates.AssociateID)
--QstnID
--Rspns
--ResponseDate

tblQuestions
--QstnID (1-many with tblResponses.QstnID)
--text
--etc

tblResponsesList
--QstnID (1-many with tblQuestions.QstnID)
--Rspns

In the listbox it shows all options in tblResponsesList that have a
corresponding QstnID to the one in tblQuestions. When selections are made in
the listbox, the results are saved to tblResponses. I am looking at wanting
the listbox to still pull from tblResponsesList, but "select" the result from
tblResponses if someone goes to review. The listbox contains the fields
Rspns and QstnID.
 
T

Tom Ellison

Dear Spokane:

The way I'd teach this is to teach debugging.

Let's display the values of ListRspns.ItemData(x) and of DLookup("Rspns",
"tblResponses", "QstnID=" & Me!QstnID) each time around the loop. Then look
for the list (make it 2 columns) in the immediate pane. What does that tell
you? (Put the debug.print just after the "For" line).

I train my own programmers, and that's the way I do it. I'm going to make
you work for it (well, a little bit) but you'll learn to find and fix your
own problems. Then I can go on vacation while you stay back at my office
and do all the work (sometimes that's what my trainees tend to think,
anyway, and it's partly true!)

You know how it should work, so let's see where it doesn't!

Tom Ellison
 
S

spokane29 via AccessMonster.com

Thank you Tom. I have been playing with the Immediate window. Being new to
the Immediate window, I am lost on a couple things. I have entered the code,
but when I attempt to run the first line:

For y = 0 To ListRspns.ListCount - 1

I get the message "Compile Error: For without Next", yet I have the Next
statement at the end of the code I am attempting to debug.

Tom said:
Dear Spokane:

The way I'd teach this is to teach debugging.

Let's display the values of ListRspns.ItemData(x) and of DLookup("Rspns",
"tblResponses", "QstnID=" & Me!QstnID) each time around the loop. Then look
for the list (make it 2 columns) in the immediate pane. What does that tell
you? (Put the debug.print just after the "For" line).

I train my own programmers, and that's the way I do it. I'm going to make
you work for it (well, a little bit) but you'll learn to find and fix your
own problems. Then I can go on vacation while you stay back at my office
and do all the work (sometimes that's what my trainees tend to think,
anyway, and it's partly true!)

You know how it should work, so let's see where it doesn't!

Tom Ellison
I have a listbox that has the following SQL in a query:
[quoted text clipped - 52 lines]
tblResponses if someone goes to review. The listbox contains the fields
Rspns and QstnID.
 
T

Tom Ellison

Dear Spokane:

I was not suggesting you put the code in the immediate pane, but put the
debug.print code into your code, temporarily. Then, view the results after
it has run, perhaps by putting a breakpoint in the code when it leave the
loop.

Tom Ellison


spokane29 via AccessMonster.com said:
Thank you Tom. I have been playing with the Immediate window. Being new
to
the Immediate window, I am lost on a couple things. I have entered the
code,
but when I attempt to run the first line:

For y = 0 To ListRspns.ListCount - 1

I get the message "Compile Error: For without Next", yet I have the Next
statement at the end of the code I am attempting to debug.

Tom said:
Dear Spokane:

The way I'd teach this is to teach debugging.

Let's display the values of ListRspns.ItemData(x) and of DLookup("Rspns",
"tblResponses", "QstnID=" & Me!QstnID) each time around the loop. Then
look
for the list (make it 2 columns) in the immediate pane. What does that
tell
you? (Put the debug.print just after the "For" line).

I train my own programmers, and that's the way I do it. I'm going to make
you work for it (well, a little bit) but you'll learn to find and fix your
own problems. Then I can go on vacation while you stay back at my office
and do all the work (sometimes that's what my trainees tend to think,
anyway, and it's partly true!)

You know how it should work, so let's see where it doesn't!

Tom Ellison
I have a listbox that has the following SQL in a query:
[quoted text clipped - 52 lines]
tblResponses if someone goes to review. The listbox contains the fields
Rspns and QstnID.
 
S

spokane29 via AccessMonster.com

I kind of figured that after I posted the message. The results in the
Immediate window actually have me baffled. It is advancing line, but no data.
Hmm...will have to try and stress my brain on this on.

Tom said:
Dear Spokane:

I was not suggesting you put the code in the immediate pane, but put the
debug.print code into your code, temporarily. Then, view the results after
it has run, perhaps by putting a breakpoint in the code when it leave the
loop.

Tom Ellison
Thank you Tom. I have been playing with the Immediate window. Being new
to
[quoted text clipped - 33 lines]
 
T

Tom Ellison

Dear Spokane:

That's the method to my madness. I get you to find your own problem and
figure out how to fix it.

Also, if it were my problem, I would likely do the same thing.

So, now you have the tools to proceed. If you find where the malfunction
is, but don't know how to fix it, you have the start of a new thread, with a
new and very specific question.

It's the old, "give a man a fish . . ." paradigm. Hopefully, you now have a
fishing pole.

Tom Ellison


spokane29 via AccessMonster.com said:
I kind of figured that after I posted the message. The results in the
Immediate window actually have me baffled. It is advancing line, but no
data.
Hmm...will have to try and stress my brain on this on.

Tom said:
Dear Spokane:

I was not suggesting you put the code in the immediate pane, but put the
debug.print code into your code, temporarily. Then, view the results
after
it has run, perhaps by putting a breakpoint in the code when it leave the
loop.

Tom Ellison
Thank you Tom. I have been playing with the Immediate window. Being
new
to
[quoted text clipped - 33 lines]
tblResponses if someone goes to review. The listbox contains the
fields
Rspns and QstnID.
 

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