reset listboxes

G

Guest

Hi!

In a form, I have two listboxes. The user selects one option from any of the
two boxes and then clicks on a preview or print button to view a report. Each
option opens a different report.

When I select one of the listboxes, I want the other one to be reseted and
have no item selected.

I tried many ways to do this and it worked perfectly. The listbox was
reseted, but then, my preview and print button no longer work. I get no error
but when I click on these buttons, nothing happens... However, when there was
no code for reseting the listboxes, the print and preview buttons worked if
only one option from the listboxes wa selected.

Can someone help me out? I work in access 2000

Here's my code: the print and preview buttons were created the same way as
the buttons used in the NorthWind access examples. The default value of the
two listboxes is none selected.

sub PrintReports(Printmode As Integer)
dim ReportName, Condition As String

select case Me!List1 & Me!List2
Case "employees report"
ReportName="EmployeesReport"
Condition=""
'.....
Case "Vehicule report"
'..... and so on...
end select
docmd.openreport ReportName, Printmode, , Condition
end sub

' Here'S the code I designed for reseting the other listbox while one has
the focus

Private Sub List1_Click()

dim n As integer

for n=1 to me.list2.listcount
me.list2.selected(n) =false
next n

end sub
' I also tried Me.list2.defaultvalue =true (Where the default value is none
selected) and it also worked for the reseting part. But then, as I said,
print doesn't work anymore

thanks for helping

Louis Pat
 
G

Guest

Hi.

A ListBox that has no items selected can still have a value. When you click
the Preview Button, Me!List1 & Me!List2 is probably evaluating to a string
containing the names of the last report clicked in each ListBox, and not just
the one report that is selected. To illustrate this, place a line of code in
your "PrintReports" procedure that says:
Debug.Print Me!List1 & Me!List2
and then check the Immediate Window (CTRL-G) after clicking the Print button.

To fix the problem, you could try setting the value of each ListBox to an
empty string when the other one is clicked. Place this line:
Me.List2.Value = ""
in your List1_Click event, and place this line:
Me.List1.Value = ""
in your List2_Click event.

This may solve the problem. However, I'm not sure why:
1. It was working before the Reset code was added
2. You did not receive any errors when trying to print after the Reset code
was added.

-Michael
 

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