Am I close on this???

N

Nancy

I have created a form for my customer to enter their selection criteria of
custid. This field is a list box tied to a table. Once the customer selects
something, I have the following after update event attached to the list box:

Private Sub cust_AfterUpdate()
Dim strWhere As String
Dim stDocument As String

If Not IsNull(Me.CUST) Then
strWhere = "[custid] = " & Me.CUST
stDocument = "test"
DoCmd.OpenReport stDocument, acPreview, strWhere
End If

End Sub

1. Am I close on my code?
2. Do I need to do something to the report to to accept the values I am
passing in?

Thanks for all of your help!
 
A

Allen Browne

You missed one comma:
DoCmd.OpenReport stDocument, acPreview, , strWhere

If the list box is bound to a field, the record needs to be saved before you
open the report:
RunCommand acCmdSaveRecord

If this is an unbound list box where the user can select multiple customers
for the report, see:
http://allenbrowne.com/ser-50.html
 
N

Nancy

Allen,

I corrected this line but it still did not work. It did not return any
data. Is there something I am suppose to do inside of the report? I just
selected 3 fields (one being the custid), all coming from one table. Nothing
fancy.

Any help is appriciated.

Thanks,


Allen Browne said:
You missed one comma:
DoCmd.OpenReport stDocument, acPreview, , strWhere

If the list box is bound to a field, the record needs to be saved before you
open the report:
RunCommand acCmdSaveRecord

If this is an unbound list box where the user can select multiple customers
for the report, see:
http://allenbrowne.com/ser-50.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Nancy said:
I have created a form for my customer to enter their selection criteria of
custid. This field is a list box tied to a table. Once the customer
selects
something, I have the following after update event attached to the list
box:

Private Sub cust_AfterUpdate()
Dim strWhere As String
Dim stDocument As String

If Not IsNull(Me.CUST) Then
strWhere = "[custid] = " & Me.CUST
stDocument = "test"
DoCmd.OpenReport stDocument, acPreview, strWhere
End If

End Sub

1. Am I close on my code?
2. Do I need to do something to the report to to accept the values I am
passing in?

Thanks for all of your help!
 
A

Allen Browne

I take it the report opens, but display no records.
You are therefore seeking to debug this, and find out why.

Add this line to your code, just above the OpenReport:
Debug.Print strWhere

After opening the report, press Ctrl+G to open the Immediate Window.
Does it show the correct filter?

Has the record been saved before you open the report?

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Nancy said:
Allen,

I corrected this line but it still did not work. It did not return any
data. Is there something I am suppose to do inside of the report? I just
selected 3 fields (one being the custid), all coming from one table.
Nothing
fancy.

Any help is appriciated.

Thanks,


Allen Browne said:
You missed one comma:
DoCmd.OpenReport stDocument, acPreview, , strWhere

If the list box is bound to a field, the record needs to be saved before
you
open the report:
RunCommand acCmdSaveRecord

If this is an unbound list box where the user can select multiple
customers
for the report, see:
http://allenbrowne.com/ser-50.html

Nancy said:
I have created a form for my customer to enter their selection criteria
of
custid. This field is a list box tied to a table. Once the customer
selects
something, I have the following after update event attached to the list
box:

Private Sub cust_AfterUpdate()
Dim strWhere As String
Dim stDocument As String

If Not IsNull(Me.CUST) Then
strWhere = "[custid] = " & Me.CUST
stDocument = "test"
DoCmd.OpenReport stDocument, acPreview, strWhere
End If

End Sub

1. Am I close on my code?
2. Do I need to do something to the report to to accept the values I am
passing in?

Thanks for all of your help!
 
N

Nancy

Allen -

My strWhere clause is correct right before I leave my form. However when I
enter my report and press Ctrl+G the filter is empty. I am passing it as one
of my parameters but it appears I am not recieving it on the report end.

Is there something else I can do to help me debug this? Is there something
I should be doing on the report end to accept the field?

I feel as if I am missing a step.

Thank you for all of your help.



Allen Browne said:
I take it the report opens, but display no records.
You are therefore seeking to debug this, and find out why.

Add this line to your code, just above the OpenReport:
Debug.Print strWhere

After opening the report, press Ctrl+G to open the Immediate Window.
Does it show the correct filter?

Has the record been saved before you open the report?

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Nancy said:
Allen,

I corrected this line but it still did not work. It did not return any
data. Is there something I am suppose to do inside of the report? I just
selected 3 fields (one being the custid), all coming from one table.
Nothing
fancy.

Any help is appriciated.

Thanks,


Allen Browne said:
You missed one comma:
DoCmd.OpenReport stDocument, acPreview, , strWhere

If the list box is bound to a field, the record needs to be saved before
you
open the report:
RunCommand acCmdSaveRecord

If this is an unbound list box where the user can select multiple
customers
for the report, see:
http://allenbrowne.com/ser-50.html

I have created a form for my customer to enter their selection criteria
of
custid. This field is a list box tied to a table. Once the customer
selects
something, I have the following after update event attached to the list
box:

Private Sub cust_AfterUpdate()
Dim strWhere As String
Dim stDocument As String

If Not IsNull(Me.CUST) Then
strWhere = "[custid] = " & Me.CUST
stDocument = "test"
DoCmd.OpenReport stDocument, acPreview, strWhere
End If

End Sub

1. Am I close on my code?
2. Do I need to do something to the report to to accept the values I am
passing in?

Thanks for all of your help!
 
A

Allen Browne

Make sure the report was not already open: not even in design view.

If it's already open, the OpenReport doesn't get to do its stuff.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Nancy said:
Allen -

My strWhere clause is correct right before I leave my form. However when
I
enter my report and press Ctrl+G the filter is empty. I am passing it as
one
of my parameters but it appears I am not recieving it on the report end.

Is there something else I can do to help me debug this? Is there
something
I should be doing on the report end to accept the field?

I feel as if I am missing a step.

Thank you for all of your help.



Allen Browne said:
I take it the report opens, but display no records.
You are therefore seeking to debug this, and find out why.

Add this line to your code, just above the OpenReport:
Debug.Print strWhere

After opening the report, press Ctrl+G to open the Immediate Window.
Does it show the correct filter?

Has the record been saved before you open the report?

Nancy said:
Allen,

I corrected this line but it still did not work. It did not return any
data. Is there something I am suppose to do inside of the report? I
just
selected 3 fields (one being the custid), all coming from one table.
Nothing
fancy.

Any help is appriciated.

Thanks,


:

You missed one comma:
DoCmd.OpenReport stDocument, acPreview, , strWhere

If the list box is bound to a field, the record needs to be saved
before
you
open the report:
RunCommand acCmdSaveRecord

If this is an unbound list box where the user can select multiple
customers
for the report, see:
http://allenbrowne.com/ser-50.html

I have created a form for my customer to enter their selection
criteria
of
custid. This field is a list box tied to a table. Once the
customer
selects
something, I have the following after update event attached to the
list
box:

Private Sub cust_AfterUpdate()
Dim strWhere As String
Dim stDocument As String

If Not IsNull(Me.CUST) Then
strWhere = "[custid] = " & Me.CUST
stDocument = "test"
DoCmd.OpenReport stDocument, acPreview, strWhere
End If

End Sub

1. Am I close on my code?
2. Do I need to do something to the report to to accept the values I
am
passing in?

Thanks for all of your help!
 

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