Data printing

T

terry

I have a form with one field in it called CondolenceID and 1 list box called
myctl

below is the code I am using to select a report from the list box the
problem is it works some time and then other times it prints all records or
the form its self

Any ideas why it is intermiting ?


Private Sub Command24_Click()
Dim StrWhere As String
StrWhere = "[condolenceID]=""" & Me!CondolenceID & """"
Dim VarItm As Variant
For Each VarItm In myctl.ItemsSelected
DoCmd.OpenReport myctl.ItemData(VarItm), acPreview, , StrWhere
Next


End Sub
 
P

PieterLinden via AccessMonster.com

terry said:
I have a form with one field in it called CondolenceID and 1 list box called
myctl

below is the code I am using to select a report from the list box the
problem is it works some time and then other times it prints all records or
the form its self

Any ideas why it is intermiting ?

Private Sub Command24_Click()
Dim StrWhere As String
StrWhere = "[condolenceID]=""" & Me!CondolenceID & """"
Dim VarItm As Variant
For Each VarItm In myctl.ItemsSelected
DoCmd.OpenReport myctl.ItemData(VarItm), acPreview, , StrWhere
Next


End Sub

looks like your filter is wrong. If CondolenceID is numeric, then the filter
should be like this:

strWhere = "[condolenceID]=" & Me!CondolenceID

If CondolenceID is a text value, then it's

strWhere = "[condolenceID]= '" & Me!CondolenceID & "'"
 
T

terry

Thank you for the help the value of CondolenceID would be numeric and text
Example 9013-Jones
--
Terry


PieterLinden via AccessMonster.com said:
terry said:
I have a form with one field in it called CondolenceID and 1 list box called
myctl

below is the code I am using to select a report from the list box the
problem is it works some time and then other times it prints all records or
the form its self

Any ideas why it is intermiting ?

Private Sub Command24_Click()
Dim StrWhere As String
StrWhere = "[condolenceID]=""" & Me!CondolenceID & """"
Dim VarItm As Variant
For Each VarItm In myctl.ItemsSelected
DoCmd.OpenReport myctl.ItemData(VarItm), acPreview, , StrWhere
Next


End Sub

looks like your filter is wrong. If CondolenceID is numeric, then the filter
should be like this:

strWhere = "[condolenceID]=" & Me!CondolenceID

If CondolenceID is a text value, then it's

strWhere = "[condolenceID]= '" & Me!CondolenceID & "'"
 
P

PieterLinden via AccessMonster.com

terry said:
Thank you for the help the value of CondolenceID would be numeric and text
Example 9013-Jones[quoted text clipped - 24 lines]
strWhere = "[condolenceID]= '" & Me!CondolenceID & "'"

No such thing. Depends on the field type in the table. If the field type is
text, you have to surround the value of (me.CondolenceID) in single quotes,
otherwise, if it's numeric, you don't.
 
T

terry

Thank you for all the help I have gone back and modified the table and
changed condolenceID to number and change our format so that we enter only
the numeric value and it is working prefectly. I change the str line to read
strWhere = "[condolenceID]=" & Me!CondolenceID
as you suggested

Thank you again for the help
--
Terry


PieterLinden via AccessMonster.com said:
terry said:
Thank you for the help the value of CondolenceID would be numeric and text
Example 9013-Jones
I have a form with one field in it called CondolenceID and 1 list box called
myctl
[quoted text clipped - 24 lines]
strWhere = "[condolenceID]= '" & Me!CondolenceID & "'"

No such thing. Depends on the field type in the table. If the field type is
text, you have to surround the value of (me.CondolenceID) in single quotes,
otherwise, if it's numeric, you don't.
 
J

John W. Vinson

Thank you for all the help I have gone back and modified the table and
changed condolenceID to number and change our format so that we enter only
the numeric value and it is working prefectly. I change the str line to read
strWhere = "[condolenceID]=" & Me!CondolenceID
as you suggested

Thank you again for the help

Typically you would use a Number field for the ID - but the user should never
need to enter a numeric ID, or even SEE a numeric ID!

Your form control would typically be a Combo Box, with the numeric
CondolenceID as the bound column, but a human-meaningful text name as the
displayed column.
 

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