Selecting A Record From A Listbox

M

MRL

Have a form with a list box come up when a query has more than one record,
the list box shows the possible CNC machines that the process can be run on.
I want the user to select the machine from the list and have that record
printed. Do I write code for a double click on machine selected? Have them
highlight the machine in the list & have a "PRINT" button? The latter was my
thought, a "PRINT" & a "CANCEL" button. How would the call out look for the
print command: Docmd.OpenReport.......? Need to look for the listbox result,
right!?
Thanks
 
G

Graham R Seach

I'd suggest that the preferred method would be to use a Print command
button, which is enabled when, and only when, a valid selection is made in
the ListBox.

1. Disable the command button (Enabled=False).
2. In the ListBox's Click event:
Me.cmdPrint.Enabled = (Not IsNull(Me.lstListBox))

3. In the Print command button's Click event:
DoCmd.OpenReport strReportName, , , , "MachineID = " & Me.lstListBox

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
 
M

MRL

Forgot all about the "Enable" on/off stuff, got that to work but still can't
get just the list box's highlighted machine report to print. I use the same
8 digit part number & 4 digit operation when I test the code, when the form
with the list box appears there are 2 machine options, I highlight one but it
still displays both forms when I hit the "Display" button. I'm trying to get
the listbox coding to work with the docmd.openform first, don't want to waste
a forest of paper.
Should I have something else in the "Click" procedure for the list box to
point to the highlighted machine?
I'm still plugging.
 
G

Graham R Seach

You'll have to show us how you're calling the OpenReport method, what
criteria you're using, and how that maps to the underlying table/query.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
---------------------------
 
M

MRL

Thanks for the assistance Graham, here is some of the coding in my CNC
Machine Input form, it has the list box, a cancel & a print button.

The list box is generated from the main table query as follows:
SELECT [Main Table Query].[Machine Description] FROM [Main Table Query]

Like I said, the list box will show different machines, but I cant select
one specific machine from the list & print/view the form for that machine.
The machine field is in a related table called "Machine Data Table," but
that shouldn't matter, they show on the list box.

CODE:
Private Sub CNCMachine_Lstbox_Click()
Me.bntPrint.Enabled = (Not IsNull(Me.CNCMachine_Lstbox))
End Sub
***********************************************
Private Sub bntPrint_Click()
DoCmd.OpenForm "CNC Booklet", acNormal, "Machine Description=" &
Me.CNCMachine_Lstbox
DoCmd.Close acForm, "input form", acSaveNo
DoCmd.Close acForm, "CNC Machine Input", acSaveNo
End Sub
 
G

Graham R Seach

DoCmd.OpenForm "CNC Booklet", acNormal, "[Machine Description] = """ &
Me.CNCMachine_Lstbox & """"

When the field name contains spaces, you must enclose it in square brackets.
Also, since [Machine Description] is a string, you must enclose the SQL
argument (Me.CNCMachine_Listbox) in quotes.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
---------------------------

MRL said:
Thanks for the assistance Graham, here is some of the coding in my CNC
Machine Input form, it has the list box, a cancel & a print button.

The list box is generated from the main table query as follows:
SELECT [Main Table Query].[Machine Description] FROM [Main Table Query]

Like I said, the list box will show different machines, but I cant select
one specific machine from the list & print/view the form for that machine.
The machine field is in a related table called "Machine Data Table," but
that shouldn't matter, they show on the list box.

CODE:
Private Sub CNCMachine_Lstbox_Click()
Me.bntPrint.Enabled = (Not IsNull(Me.CNCMachine_Lstbox))
End Sub
***********************************************
Private Sub bntPrint_Click()
DoCmd.OpenForm "CNC Booklet", acNormal, "Machine Description=" &
Me.CNCMachine_Lstbox
DoCmd.Close acForm, "input form", acSaveNo
DoCmd.Close acForm, "CNC Machine Input", acSaveNo
End Sub


Graham R Seach said:
You'll have to show us how you're calling the OpenReport method, what
criteria you're using, and how that maps to the underlying table/query.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
 
M

MRL

Morning Graham,
Updated the OpenForm line but still seeing both machines. Thinkin' last
night, do I need to code to re-run the query & use the input from the list
box to get only one result? Trying now to echo to the screen just what is
saved in the Me.CNCMachine_Lstbox memory. Does the Sub
CNCMachine_Lstbox_Click() put in memory what is clicked on in the listbox or
do I have to add code to do it, right now the only code is the "Enable" code
for the Print Button.
MRL from NH,USA

Graham R Seach said:
DoCmd.OpenForm "CNC Booklet", acNormal, "[Machine Description] = """ &
Me.CNCMachine_Lstbox & """"

When the field name contains spaces, you must enclose it in square brackets.
Also, since [Machine Description] is a string, you must enclose the SQL
argument (Me.CNCMachine_Listbox) in quotes.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
---------------------------

MRL said:
Thanks for the assistance Graham, here is some of the coding in my CNC
Machine Input form, it has the list box, a cancel & a print button.

The list box is generated from the main table query as follows:
SELECT [Main Table Query].[Machine Description] FROM [Main Table Query]

Like I said, the list box will show different machines, but I cant select
one specific machine from the list & print/view the form for that machine.
The machine field is in a related table called "Machine Data Table," but
that shouldn't matter, they show on the list box.

CODE:
Private Sub CNCMachine_Lstbox_Click()
Me.bntPrint.Enabled = (Not IsNull(Me.CNCMachine_Lstbox))
End Sub
***********************************************
Private Sub bntPrint_Click()
DoCmd.OpenForm "CNC Booklet", acNormal, "Machine Description=" &
Me.CNCMachine_Lstbox
DoCmd.Close acForm, "input form", acSaveNo
DoCmd.Close acForm, "CNC Machine Input", acSaveNo
End Sub


Graham R Seach said:
You'll have to show us how you're calling the OpenReport method, what
criteria you're using, and how that maps to the underlying table/query.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
---------------------------

Forgot all about the "Enable" on/off stuff, got that to work but still
can't
get just the list box's highlighted machine report to print. I use the
same
8 digit part number & 4 digit operation when I test the code, when the
form
with the list box appears there are 2 machine options, I highlight one
but
it
still displays both forms when I hit the "Display" button. I'm trying
to
get
the listbox coding to work with the docmd.openform first, don't want to
waste
a forest of paper.
Should I have something else in the "Click" procedure for the list box
to
point to the highlighted machine?
I'm still plugging.
:

I'd suggest that the preferred method would be to use a Print command
button, which is enabled when, and only when, a valid selection is
made
in
the ListBox.

1. Disable the command button (Enabled=False).
2. In the ListBox's Click event:
Me.cmdPrint.Enabled = (Not IsNull(Me.lstListBox))

3. In the Print command button's Click event:
DoCmd.OpenReport strReportName, , , , "MachineID = " &
Me.lstListBox

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
---------------------------

Have a form with a list box come up when a query has more than one
record,
the list box shows the possible CNC machines that the process can be
run
on.
I want the user to select the machine from the list and have that
record
printed. Do I write code for a double click on machine selected?
Have
them
highlight the machine in the list & have a "PRINT" button? The
latter
was
my
thought, a "PRINT" & a "CANCEL" button. How would the call out look
for
the
print command: Docmd.OpenReport.......? Need to look for the
listbox
result,
right!?
Thanks
 
M

MRL

A MsgBox shows that what I highlight in the list box is stored in
Me.CNCMachine_Lstbox, that's a start. For the heck of it I'm going to run
the query using the list box as criteria for the machine description field.

Graham R Seach said:
DoCmd.OpenForm "CNC Booklet", acNormal, "[Machine Description] = """ &
Me.CNCMachine_Lstbox & """"

When the field name contains spaces, you must enclose it in square brackets.
Also, since [Machine Description] is a string, you must enclose the SQL
argument (Me.CNCMachine_Listbox) in quotes.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
---------------------------

MRL said:
Thanks for the assistance Graham, here is some of the coding in my CNC
Machine Input form, it has the list box, a cancel & a print button.

The list box is generated from the main table query as follows:
SELECT [Main Table Query].[Machine Description] FROM [Main Table Query]

Like I said, the list box will show different machines, but I cant select
one specific machine from the list & print/view the form for that machine.
The machine field is in a related table called "Machine Data Table," but
that shouldn't matter, they show on the list box.

CODE:
Private Sub CNCMachine_Lstbox_Click()
Me.bntPrint.Enabled = (Not IsNull(Me.CNCMachine_Lstbox))
End Sub
***********************************************
Private Sub bntPrint_Click()
DoCmd.OpenForm "CNC Booklet", acNormal, "Machine Description=" &
Me.CNCMachine_Lstbox
DoCmd.Close acForm, "input form", acSaveNo
DoCmd.Close acForm, "CNC Machine Input", acSaveNo
End Sub


Graham R Seach said:
You'll have to show us how you're calling the OpenReport method, what
criteria you're using, and how that maps to the underlying table/query.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
---------------------------

Forgot all about the "Enable" on/off stuff, got that to work but still
can't
get just the list box's highlighted machine report to print. I use the
same
8 digit part number & 4 digit operation when I test the code, when the
form
with the list box appears there are 2 machine options, I highlight one
but
it
still displays both forms when I hit the "Display" button. I'm trying
to
get
the listbox coding to work with the docmd.openform first, don't want to
waste
a forest of paper.
Should I have something else in the "Click" procedure for the list box
to
point to the highlighted machine?
I'm still plugging.
:

I'd suggest that the preferred method would be to use a Print command
button, which is enabled when, and only when, a valid selection is
made
in
the ListBox.

1. Disable the command button (Enabled=False).
2. In the ListBox's Click event:
Me.cmdPrint.Enabled = (Not IsNull(Me.lstListBox))

3. In the Print command button's Click event:
DoCmd.OpenReport strReportName, , , , "MachineID = " &
Me.lstListBox

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
---------------------------

Have a form with a list box come up when a query has more than one
record,
the list box shows the possible CNC machines that the process can be
run
on.
I want the user to select the machine from the list and have that
record
printed. Do I write code for a double click on machine selected?
Have
them
highlight the machine in the list & have a "PRINT" button? The
latter
was
my
thought, a "PRINT" & a "CANCEL" button. How would the call out look
for
the
print command: Docmd.OpenReport.......? Need to look for the
listbox
result,
right!?
Thanks
 
M

MRL

Got it Graham, needed a "Main Table Query" prior to the field callout. May be
a good Tuesday after all.
Thanks Again!!!!!!

Graham R Seach said:
DoCmd.OpenForm "CNC Booklet", acNormal, "[Machine Description] = """ &
Me.CNCMachine_Lstbox & """"

When the field name contains spaces, you must enclose it in square brackets.
Also, since [Machine Description] is a string, you must enclose the SQL
argument (Me.CNCMachine_Listbox) in quotes.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
---------------------------

MRL said:
Thanks for the assistance Graham, here is some of the coding in my CNC
Machine Input form, it has the list box, a cancel & a print button.

The list box is generated from the main table query as follows:
SELECT [Main Table Query].[Machine Description] FROM [Main Table Query]

Like I said, the list box will show different machines, but I cant select
one specific machine from the list & print/view the form for that machine.
The machine field is in a related table called "Machine Data Table," but
that shouldn't matter, they show on the list box.

CODE:
Private Sub CNCMachine_Lstbox_Click()
Me.bntPrint.Enabled = (Not IsNull(Me.CNCMachine_Lstbox))
End Sub
***********************************************
Private Sub bntPrint_Click()
DoCmd.OpenForm "CNC Booklet", acNormal, "Machine Description=" &
Me.CNCMachine_Lstbox
DoCmd.Close acForm, "input form", acSaveNo
DoCmd.Close acForm, "CNC Machine Input", acSaveNo
End Sub


Graham R Seach said:
You'll have to show us how you're calling the OpenReport method, what
criteria you're using, and how that maps to the underlying table/query.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
---------------------------

Forgot all about the "Enable" on/off stuff, got that to work but still
can't
get just the list box's highlighted machine report to print. I use the
same
8 digit part number & 4 digit operation when I test the code, when the
form
with the list box appears there are 2 machine options, I highlight one
but
it
still displays both forms when I hit the "Display" button. I'm trying
to
get
the listbox coding to work with the docmd.openform first, don't want to
waste
a forest of paper.
Should I have something else in the "Click" procedure for the list box
to
point to the highlighted machine?
I'm still plugging.
:

I'd suggest that the preferred method would be to use a Print command
button, which is enabled when, and only when, a valid selection is
made
in
the ListBox.

1. Disable the command button (Enabled=False).
2. In the ListBox's Click event:
Me.cmdPrint.Enabled = (Not IsNull(Me.lstListBox))

3. In the Print command button's Click event:
DoCmd.OpenReport strReportName, , , , "MachineID = " &
Me.lstListBox

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
---------------------------

Have a form with a list box come up when a query has more than one
record,
the list box shows the possible CNC machines that the process can be
run
on.
I want the user to select the machine from the list and have that
record
printed. Do I write code for a double click on machine selected?
Have
them
highlight the machine in the list & have a "PRINT" button? The
latter
was
my
thought, a "PRINT" & a "CANCEL" button. How would the call out look
for
the
print command: Docmd.OpenReport.......? Need to look for the
listbox
result,
right!?
Thanks
 
Top