Combo box

S

Steve Moss

I have a form with 1 combo box on it. on the drop down menu there are a
number of names. when a specific name is selected how do i get it to open
thr report corresponding to that name i.e. when "Jane" is selcted from the
list, the report "jane opens"
 
O

Ofer Cohen

Look at this link on "Printing the Record on the Microsoft Access Form to a
Report"

http://www.databasedev.co.uk/report_from_form_record.html

In addition, if the filter is on a text field, change the filter adding
single quote for a string

This line:
strCriteria = "[lngSalespersonID]= " & Me![lngSalespersonID]

will turn into
strCriteria = "[lngSalespersonID]= '" & Me![lngSalespersonID] & "'"
 
S

Steve Moss

I followed the code in the link and an error comes up, the error being "RUN
TIME ERROR '424'
OBJECT REQUIRED".

the code i entered was:

Private Sub Combo4_Click()
Dim strReportName As String
Dim strCriteria As String
If NewRecord Then
MsgBox "This record contains no data." _
, vbInformation, "Invalid Action"
Exit Sub
Else
strReportName = [Combo4]
strCriteria = "[Combo4] =" & Me![Combo4] & ""
DoComd.OpenReport strReportName, acViewPreview, strCriteria
End If
End Sub


on Debug it highlighted the "DoCmd line". i used [Combo4] as the report
name as i have a list of reports to choose from and the one i want to select
is defined by what is selected in the combo box. what am i doing wrong.


Ofer Cohen said:
Look at this link on "Printing the Record on the Microsoft Access Form to a
Report"

http://www.databasedev.co.uk/report_from_form_record.html

In addition, if the filter is on a text field, change the filter adding
single quote for a string

This line:
strCriteria = "[lngSalespersonID]= " & Me![lngSalespersonID]

will turn into
strCriteria = "[lngSalespersonID]= '" & Me![lngSalespersonID] & "'"

--
Good Luck
BS"D


Steve Moss said:
I have a form with 1 combo box on it. on the drop down menu there are a
number of names. when a specific name is selected how do i get it to open
thr report corresponding to that name i.e. when "Jane" is selcted from the
list, the report "jane opens"
 
O

Ofer Cohen

Private Sub Combo4_Click()
Dim strReportName As String
Dim strCriteria As String
If NewRecord Then
MsgBox "This record contains no data." _
, vbInformation, "Invalid Action"
Exit Sub
Else
'************************************
' Enter here the report name, instead of the combo name
' strReportName = "Report Name"
'************************************
strReportName = [Combo4]
'******************************
' In the criteria you need to have
' "[FieldNameInThe Table]='" & Me![Combo4] & "'"
' ******************************
strCriteria = "[Combo4] =" & Me![Combo4] & ""
DoComd.OpenReport strReportName, acViewPreview, strCriteria
End If

--
Good Luck
BS"D


Steve Moss said:
I followed the code in the link and an error comes up, the error being "RUN
TIME ERROR '424'
OBJECT REQUIRED".

the code i entered was:

Private Sub Combo4_Click()
Dim strReportName As String
Dim strCriteria As String
If NewRecord Then
MsgBox "This record contains no data." _
, vbInformation, "Invalid Action"
Exit Sub
Else
strReportName = [Combo4]
strCriteria = "[Combo4] =" & Me![Combo4] & ""
DoComd.OpenReport strReportName, acViewPreview, strCriteria
End If
End Sub


on Debug it highlighted the "DoCmd line". i used [Combo4] as the report
name as i have a list of reports to choose from and the one i want to select
is defined by what is selected in the combo box. what am i doing wrong.


Ofer Cohen said:
Look at this link on "Printing the Record on the Microsoft Access Form to a
Report"

http://www.databasedev.co.uk/report_from_form_record.html

In addition, if the filter is on a text field, change the filter adding
single quote for a string

This line:
strCriteria = "[lngSalespersonID]= " & Me![lngSalespersonID]

will turn into
strCriteria = "[lngSalespersonID]= '" & Me![lngSalespersonID] & "'"

--
Good Luck
BS"D


Steve Moss said:
I have a form with 1 combo box on it. on the drop down menu there are a
number of names. when a specific name is selected how do i get it to open
thr report corresponding to that name i.e. when "Jane" is selcted from the
list, the report "jane opens"
 
S

Steve Moss

I am not sure what you mean. The Reports i have are "Bosun" "CO" "COXN"
"DMEO". in the drop down menu of the Combo box i have the values "Bosun"
"CO" "COXN" "DMEO". If i want to view the "CO" Report i would select the
"CO" value. i dont have a specific Report name until i select it in the drop
down list.

Ofer Cohen said:
Private Sub Combo4_Click()
Dim strReportName As String
Dim strCriteria As String
If NewRecord Then
MsgBox "This record contains no data." _
, vbInformation, "Invalid Action"
Exit Sub
Else
'************************************
' Enter here the report name, instead of the combo name
' strReportName = "Report Name"
'************************************
strReportName = [Combo4]
'******************************
' In the criteria you need to have
' "[FieldNameInThe Table]='" & Me![Combo4] & "'"
' ******************************
strCriteria = "[Combo4] =" & Me![Combo4] & ""
DoComd.OpenReport strReportName, acViewPreview, strCriteria
End If

--
Good Luck
BS"D


Steve Moss said:
I followed the code in the link and an error comes up, the error being "RUN
TIME ERROR '424'
OBJECT REQUIRED".

the code i entered was:

Private Sub Combo4_Click()
Dim strReportName As String
Dim strCriteria As String
If NewRecord Then
MsgBox "This record contains no data." _
, vbInformation, "Invalid Action"
Exit Sub
Else
strReportName = [Combo4]
strCriteria = "[Combo4] =" & Me![Combo4] & ""
DoComd.OpenReport strReportName, acViewPreview, strCriteria
End If
End Sub


on Debug it highlighted the "DoCmd line". i used [Combo4] as the report
name as i have a list of reports to choose from and the one i want to select
is defined by what is selected in the combo box. what am i doing wrong.


Ofer Cohen said:
Look at this link on "Printing the Record on the Microsoft Access Form to a
Report"

http://www.databasedev.co.uk/report_from_form_record.html

In addition, if the filter is on a text field, change the filter adding
single quote for a string

This line:
strCriteria = "[lngSalespersonID]= " & Me![lngSalespersonID]

will turn into
strCriteria = "[lngSalespersonID]= '" & Me![lngSalespersonID] & "'"

--
Good Luck
BS"D


:

I have a form with 1 combo box on it. on the drop down menu there are a
number of names. when a specific name is selected how do i get it to open
thr report corresponding to that name i.e. when "Jane" is selcted from the
list, the report "jane opens"
 
D

Douglas J. Steele

It seems very strange that you have a field in the underlying recordset
named Combo4, which is what the criteria you've set indicates.

The syntax for the OpenReport method is:

DoCmd.OpenReport reportname[, view][, filtername][, wherecondition]

You're specifying a wherecondition, not a filter (filtername needs to be the
valid name of a query in the current database), so you want

DoComd.OpenReport strReportName, acViewPreview, , strCriteria


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Steve Moss said:
I followed the code in the link and an error comes up, the error being "RUN
TIME ERROR '424'
OBJECT REQUIRED".

the code i entered was:

Private Sub Combo4_Click()
Dim strReportName As String
Dim strCriteria As String
If NewRecord Then
MsgBox "This record contains no data." _
, vbInformation, "Invalid Action"
Exit Sub
Else
strReportName = [Combo4]
strCriteria = "[Combo4] =" & Me![Combo4] & ""
DoComd.OpenReport strReportName, acViewPreview, strCriteria
End If
End Sub


on Debug it highlighted the "DoCmd line". i used [Combo4] as the report
name as i have a list of reports to choose from and the one i want to
select
is defined by what is selected in the combo box. what am i doing wrong.


Ofer Cohen said:
Look at this link on "Printing the Record on the Microsoft Access Form to
a
Report"

http://www.databasedev.co.uk/report_from_form_record.html

In addition, if the filter is on a text field, change the filter adding
single quote for a string

This line:
strCriteria = "[lngSalespersonID]= " & Me![lngSalespersonID]

will turn into
strCriteria = "[lngSalespersonID]= '" & Me![lngSalespersonID] & "'"

--
Good Luck
BS"D


Steve Moss said:
I have a form with 1 combo box on it. on the drop down menu there are
a
number of names. when a specific name is selected how do i get it to
open
thr report corresponding to that name i.e. when "Jane" is selcted from
the
list, the report "jane opens"
 
O

Ofer Cohen

If you want to open the report based on the selection in the combo, and not
using the combo as a filter for the report (that what I thought you want),
then try

Private Sub Combo4_Click()
If Len(Trim(Me![Combo4]) & "")>0 Then
DoComd.OpenReport Me![Combo4], acViewPreview
Else
MsgBox "You need to select a report"
End If

End Sub

-----
Good Luck
BS"D

Steve Moss said:
I am not sure what you mean. The Reports i have are "Bosun" "CO" "COXN"
"DMEO". in the drop down menu of the Combo box i have the values "Bosun"
"CO" "COXN" "DMEO". If i want to view the "CO" Report i would select the
"CO" value. i dont have a specific Report name until i select it in the drop
down list.

Ofer Cohen said:
Private Sub Combo4_Click()
Dim strReportName As String
Dim strCriteria As String
If NewRecord Then
MsgBox "This record contains no data." _
, vbInformation, "Invalid Action"
Exit Sub
Else
'************************************
' Enter here the report name, instead of the combo name
' strReportName = "Report Name"
'************************************
strReportName = [Combo4]
'******************************
' In the criteria you need to have
' "[FieldNameInThe Table]='" & Me![Combo4] & "'"
' ******************************
strCriteria = "[Combo4] =" & Me![Combo4] & ""
DoComd.OpenReport strReportName, acViewPreview, strCriteria
End If

--
Good Luck
BS"D


Steve Moss said:
I followed the code in the link and an error comes up, the error being "RUN
TIME ERROR '424'
OBJECT REQUIRED".

the code i entered was:

Private Sub Combo4_Click()
Dim strReportName As String
Dim strCriteria As String
If NewRecord Then
MsgBox "This record contains no data." _
, vbInformation, "Invalid Action"
Exit Sub
Else
strReportName = [Combo4]
strCriteria = "[Combo4] =" & Me![Combo4] & ""
DoComd.OpenReport strReportName, acViewPreview, strCriteria
End If
End Sub


on Debug it highlighted the "DoCmd line". i used [Combo4] as the report
name as i have a list of reports to choose from and the one i want to select
is defined by what is selected in the combo box. what am i doing wrong.


:

Look at this link on "Printing the Record on the Microsoft Access Form to a
Report"

http://www.databasedev.co.uk/report_from_form_record.html

In addition, if the filter is on a text field, change the filter adding
single quote for a string

This line:
strCriteria = "[lngSalespersonID]= " & Me![lngSalespersonID]

will turn into
strCriteria = "[lngSalespersonID]= '" & Me![lngSalespersonID] & "'"

--
Good Luck
BS"D


:

I have a form with 1 combo box on it. on the drop down menu there are a
number of names. when a specific name is selected how do i get it to open
thr report corresponding to that name i.e. when "Jane" is selcted from the
list, the report "jane opens"
 
O

Ofer Cohen

If you want to open the report based on the selection in the combo, and not
using the combo as a filter for the report (that what I thought you want),
then try

Private Sub Combo4_Click()
If Len(Trim(Me![Combo4]) & "")>0 Then
DoComd.OpenReport Me![Combo4], acViewPreview
Else
MsgBox "You need to select a report"
End If

End Sub

-----
Good Luck
BS"D

Steve Moss said:
I am not sure what you mean. The Reports i have are "Bosun" "CO" "COXN"
"DMEO". in the drop down menu of the Combo box i have the values "Bosun"
"CO" "COXN" "DMEO". If i want to view the "CO" Report i would select the
"CO" value. i dont have a specific Report name until i select it in the drop
down list.

Ofer Cohen said:
Private Sub Combo4_Click()
Dim strReportName As String
Dim strCriteria As String
If NewRecord Then
MsgBox "This record contains no data." _
, vbInformation, "Invalid Action"
Exit Sub
Else
'************************************
' Enter here the report name, instead of the combo name
' strReportName = "Report Name"
'************************************
strReportName = [Combo4]
'******************************
' In the criteria you need to have
' "[FieldNameInThe Table]='" & Me![Combo4] & "'"
' ******************************
strCriteria = "[Combo4] =" & Me![Combo4] & ""
DoComd.OpenReport strReportName, acViewPreview, strCriteria
End If

--
Good Luck
BS"D


Steve Moss said:
I followed the code in the link and an error comes up, the error being "RUN
TIME ERROR '424'
OBJECT REQUIRED".

the code i entered was:

Private Sub Combo4_Click()
Dim strReportName As String
Dim strCriteria As String
If NewRecord Then
MsgBox "This record contains no data." _
, vbInformation, "Invalid Action"
Exit Sub
Else
strReportName = [Combo4]
strCriteria = "[Combo4] =" & Me![Combo4] & ""
DoComd.OpenReport strReportName, acViewPreview, strCriteria
End If
End Sub


on Debug it highlighted the "DoCmd line". i used [Combo4] as the report
name as i have a list of reports to choose from and the one i want to select
is defined by what is selected in the combo box. what am i doing wrong.


:

Look at this link on "Printing the Record on the Microsoft Access Form to a
Report"

http://www.databasedev.co.uk/report_from_form_record.html

In addition, if the filter is on a text field, change the filter adding
single quote for a string

This line:
strCriteria = "[lngSalespersonID]= " & Me![lngSalespersonID]

will turn into
strCriteria = "[lngSalespersonID]= '" & Me![lngSalespersonID] & "'"

--
Good Luck
BS"D


:

I have a form with 1 combo box on it. on the drop down menu there are a
number of names. when a specific name is selected how do i get it to open
thr report corresponding to that name i.e. when "Jane" is selcted from the
list, the report "jane opens"
 
S

Steve Moss

I think I am confusing myself. I think the best thing to do would be to
start again with this form. Mybe you could point me in the right direction.
My whole database is centred around 1 Table. In this table I have lists of
"Books of Reference". With different people i.e. "Bosun", "CO", "COXN" and
"DMEO" being custodian for different books. I have created a query to
display the books belonging to each of these people, with a Report created
from each query. I would like to use 1 form with 1 Combobox on it to select
which persons report I would like to look at. in the Row Source for the
Combobox i have "Bosun";"CO";"COXN";"DMEO" to choose from. how do i go about
getting this combobox to work.

I hope that is a little easier to understand.
Cheers

Douglas J. Steele said:
It seems very strange that you have a field in the underlying recordset
named Combo4, which is what the criteria you've set indicates.

The syntax for the OpenReport method is:

DoCmd.OpenReport reportname[, view][, filtername][, wherecondition]

You're specifying a wherecondition, not a filter (filtername needs to be the
valid name of a query in the current database), so you want

DoComd.OpenReport strReportName, acViewPreview, , strCriteria


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Steve Moss said:
I followed the code in the link and an error comes up, the error being "RUN
TIME ERROR '424'
OBJECT REQUIRED".

the code i entered was:

Private Sub Combo4_Click()
Dim strReportName As String
Dim strCriteria As String
If NewRecord Then
MsgBox "This record contains no data." _
, vbInformation, "Invalid Action"
Exit Sub
Else
strReportName = [Combo4]
strCriteria = "[Combo4] =" & Me![Combo4] & ""
DoComd.OpenReport strReportName, acViewPreview, strCriteria
End If
End Sub


on Debug it highlighted the "DoCmd line". i used [Combo4] as the report
name as i have a list of reports to choose from and the one i want to
select
is defined by what is selected in the combo box. what am i doing wrong.


Ofer Cohen said:
Look at this link on "Printing the Record on the Microsoft Access Form to
a
Report"

http://www.databasedev.co.uk/report_from_form_record.html

In addition, if the filter is on a text field, change the filter adding
single quote for a string

This line:
strCriteria = "[lngSalespersonID]= " & Me![lngSalespersonID]

will turn into
strCriteria = "[lngSalespersonID]= '" & Me![lngSalespersonID] & "'"

--
Good Luck
BS"D


:

I have a form with 1 combo box on it. on the drop down menu there are
a
number of names. when a specific name is selected how do i get it to
open
thr report corresponding to that name i.e. when "Jane" is selcted from
the
list, the report "jane opens"
 
O

Ofer Cohen

I just noticed that, the DoComd has an extra o, use DoCmd


DoCmd.OpenReport Me![Combo4], acViewPreview


Steve Moss said:
Thanks Ofer
I have just tried that code and it still comes up with the error on the line:-
DoComd.OpenReport Me![Combo4], acViewPreview

Ofer Cohen said:
If you want to open the report based on the selection in the combo, and not
using the combo as a filter for the report (that what I thought you want),
then try

Private Sub Combo4_Click()
If Len(Trim(Me![Combo4]) & "")>0 Then
DoComd.OpenReport Me![Combo4], acViewPreview
Else
MsgBox "You need to select a report"
End If

End Sub

-----
Good Luck
BS"D

Steve Moss said:
I am not sure what you mean. The Reports i have are "Bosun" "CO" "COXN"
"DMEO". in the drop down menu of the Combo box i have the values "Bosun"
"CO" "COXN" "DMEO". If i want to view the "CO" Report i would select the
"CO" value. i dont have a specific Report name until i select it in
the
drop
down list.

:

Private Sub Combo4_Click()
Dim strReportName As String
Dim strCriteria As String
If NewRecord Then
MsgBox "This record contains no data." _
, vbInformation, "Invalid Action"
Exit Sub
Else
'************************************
' Enter here the report name, instead of the combo name
' strReportName = "Report Name"
'************************************
strReportName = [Combo4]
'******************************
' In the criteria you need to have
' "[FieldNameInThe Table]='" & Me![Combo4] & "'"
' ******************************
strCriteria = "[Combo4] =" & Me![Combo4] & ""
DoComd.OpenReport strReportName, acViewPreview, strCriteria
End If

--
Good Luck
BS"D


:

I followed the code in the link and an error comes up, the error
being
"RUN
TIME ERROR '424'
OBJECT REQUIRED".

the code i entered was:

Private Sub Combo4_Click()
Dim strReportName As String
Dim strCriteria As String
If NewRecord Then
MsgBox "This record contains no data." _
, vbInformation, "Invalid Action"
Exit Sub
Else
strReportName = [Combo4]
strCriteria = "[Combo4] =" & Me![Combo4] & ""
DoComd.OpenReport strReportName, acViewPreview, strCriteria
End If
End Sub


on Debug it highlighted the "DoCmd line". i used [Combo4] as the report
name as i have a list of reports to choose from and the one i want
to
select
is defined by what is selected in the combo box. what am i doing wrong.


:

Look at this link on "Printing the Record on the Microsoft
Access
Form to a
Report"

http://www.databasedev.co.uk/report_from_form_record.html

In addition, if the filter is on a text field, change the filter adding
single quote for a string

This line:
strCriteria = "[lngSalespersonID]= " & Me![lngSalespersonID]

will turn into
strCriteria = "[lngSalespersonID]= '" & Me![lngSalespersonID] & "'"

--
Good Luck
BS"D


:

I have a form with 1 combo box on it. on the drop down menu
there
are a
number of names. when a specific name is selected how do i
get it
to open
thr report corresponding to that name i.e. when "Jane" is
selcted
from the
list, the report "jane opens"
 
D

Douglas J. Steele

I'd recommend adding a button and using that to launch the report, not
simply choosing something from the combo box:

Private Sub MyButton_Click()
Dim strReportName As String
Dim strCriteria As String

If IsNull(Me![Combo4]) Then
MsgBox "You must select a custodian.", _
vbInformation, "Invalid Action"
Else
strReportName = "NameOfReport"
strCriteria = "[Custodian] ='" & Me![Combo4] & "'"
DoComd.OpenReport strReportName, acViewPreview, ,strCriteria
End If

End Sub

This assumes that there's a field in your table named Custodian.

Note that since you're dealing with text data, that line is

strCriteria = "[Custodian] =' " & Me![Combo4] & " ' "

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Steve Moss said:
I think I am confusing myself. I think the best thing to do would be to
start again with this form. Mybe you could point me in the right
direction.
My whole database is centred around 1 Table. In this table I have lists
of
"Books of Reference". With different people i.e. "Bosun", "CO", "COXN"
and
"DMEO" being custodian for different books. I have created a query to
display the books belonging to each of these people, with a Report created
from each query. I would like to use 1 form with 1 Combobox on it to
select
which persons report I would like to look at. in the Row Source for the
Combobox i have "Bosun";"CO";"COXN";"DMEO" to choose from. how do i go
about
getting this combobox to work.

I hope that is a little easier to understand.
Cheers

Douglas J. Steele said:
It seems very strange that you have a field in the underlying recordset
named Combo4, which is what the criteria you've set indicates.

The syntax for the OpenReport method is:

DoCmd.OpenReport reportname[, view][, filtername][, wherecondition]

You're specifying a wherecondition, not a filter (filtername needs to be
the
valid name of a query in the current database), so you want

DoComd.OpenReport strReportName, acViewPreview, , strCriteria


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Steve Moss said:
I followed the code in the link and an error comes up, the error being
"RUN
TIME ERROR '424'
OBJECT REQUIRED".

the code i entered was:

Private Sub Combo4_Click()
Dim strReportName As String
Dim strCriteria As String
If NewRecord Then
MsgBox "This record contains no data." _
, vbInformation, "Invalid Action"
Exit Sub
Else
strReportName = [Combo4]
strCriteria = "[Combo4] =" & Me![Combo4] & ""
DoComd.OpenReport strReportName, acViewPreview, strCriteria
End If
End Sub


on Debug it highlighted the "DoCmd line". i used [Combo4] as the
report
name as i have a list of reports to choose from and the one i want to
select
is defined by what is selected in the combo box. what am i doing
wrong.


:

Look at this link on "Printing the Record on the Microsoft Access Form
to
a
Report"

http://www.databasedev.co.uk/report_from_form_record.html

In addition, if the filter is on a text field, change the filter
adding
single quote for a string

This line:
strCriteria = "[lngSalespersonID]= " & Me![lngSalespersonID]

will turn into
strCriteria = "[lngSalespersonID]= '" & Me![lngSalespersonID] & "'"

--
Good Luck
BS"D


:

I have a form with 1 combo box on it. on the drop down menu there
are
a
number of names. when a specific name is selected how do i get it
to
open
thr report corresponding to that name i.e. when "Jane" is selcted
from
the
list, the report "jane opens"
 
Top