print report according to value field

  • Thread starter bigwillno2 via AccessMonster.com
  • Start date
B

bigwillno2 via AccessMonster.com

I am trying to print a report depending on a the field "OrderQty". i did
created the code with the print command and the criteria and it looks like
this:

DoCmd.OpenReport "rptProduction", acViewPreview, WhereCondition:=strWhere,
OpenArgs:=strDescrip
DoCmd.PrintOut , , , , [OrderQty]

however, it give me an error saying, that "|" field is not found. i looked
through the code and tested the code, by putting 1 or 2 in place of OrderQty
and it prints fine, that means to me that it's not the code and i looked to
through the Query that the source of that Report and find no buggie field
with the name "|" and i looked in the report for the same field and i find
nothing...now i dont know where to look. Does anyone has any idea on where am
going wrong with this.
 
G

Guest

Where do you expect OrderQty to come from? Do you have a control on your form
with the code named OrderQty?
 
B

bigwillno2 via AccessMonster.com

Thanks for responding Duane,

OrderQty comes from Query named qrProduction and same query is the row source
of a multiselect list box on a form and OrderQty is also located in this list.
on the form, i have a cmd button that has the click even that carries the
printout proceedure. the source of the report that's being printed is also
the qrProduction. any thoughts? where am i going wrong?, it's this detailed
enough. the code is bellow,

Dim varItem As Variant 'Selected items
Dim strWhere As String 'String to use as WhereCondition
Dim strDescrip As String 'Description of WhereCondition
Dim lngLen As Long 'Length of string
Dim strDelim As String 'Delimiter for this field type.
Dim strDoc As String 'Name of report to open.
Dim strLabel As String
Dim prm_sched As Control
Dim DBS As Database
Dim rst As Recordset


Set prm_sched = Me![sched]

If prm_sched.ItemsSelected.Count = 0 Then
Beep
MsgBox "no item selected ", 48
Exit Sub
End If
Set DBS = CodeDb
Set rst = DBS.OpenRecordset("SELECT * FROM POhistory")

'run through all selected items
For Each varItem In prm_sched.ItemsSelected
rst.AddNew
rst!OrderNo = prm_sched.Column(0)
rst!RequiredDate = prm_sched.Column(1)
rst!CustomerID = prm_sched.Column(2)
rst!ModelNumber = prm_sched.Column(3)
rst!Description = prm_sched.Column(4)
rst!OrderQty = prm_sched.Column(5)
rst!Comment = prm_sched.Column(6)
rst!Bfill = prm_sched.Column(7)
rst!Qfill = prm_sched.Column(8)
rst!Uphfill = prm_sched.Column(9)
rst!Ptfill = prm_sched.Column(10)
rst!Spring = prm_sched.Column(11)
rst!Label = prm_sched.Column(12)
rst!Size = prm_sched.Column(13)
rst!Needle = prm_sched.Column(14)
rst!Pattern = prm_sched.Column(15)
rst!Config = prm_sched.Column(16)
rst!Border = prm_sched.Column(17)
rst!Border = prm_sched.Column(18)
rst!FoamCore = prm_sched.Column(19)
rst!FoamEnc = prm_sched.Column(20)
rst.update
Next
' strDelim = "" 'Delimiter appropriate to field type. See note 1.

strDoc = "rptProduction"
strLabel = "rptProductionLabel"
'Loop through the ItemsSelected in the list box.
If Me.sched.ItemsSelected.Count = 0 Then
Beep
MsgBox "no item selected ", 48
Exit Sub
End If
With Me.sched
For Each varItem In .ItemsSelected
If Not IsNull(varItem) Then
'Build up the filter from the bound column (hidden).
strWhere = strWhere & strDelim & .ItemData(varItem) &
strDelim & ","
'Build up the description from the text in the visible column.
See note 2.
'strDescrip = strDescrip & """" & .Column(1, varItem) & """,
"
End If
Next
End With

'Remove trailing comma. Add field name, IN operator, and brackets.
lngLen = Len(strWhere) - 1
If lngLen > 0 Then
strWhere = "[OrderNo] IN (" & Left$(strWhere, lngLen) & ")"
lngLen = Len(strDescrip) - 4
If lngLen > 0 Then
'strDescrip = "Production Required: " & Left$(strDescrip, lngLen)
End If
End If
'Report will not filter if open, so close it. For Access 97, see note 3.
If CurrentProject.AllReports(strDoc).IsLoaded Then
DoCmd.close acReport, strDoc
End If
'Omit the last argument for Access 2000 and earlier. See note 4.
DoCmd.OpenReport "rptProduction", acViewPreview, WhereCondition:=strWhere,
OpenArgs:=strDescrip
DoCmd.PrintOut , , , , [OrderQty]

i also tried it with this code bellow that doesnt have the strWhere and it
gives me the same error
Dim strProductID As String
Dim strCriteriaProductID As String
Dim strCriteriaOrderNo As String

If NewRecord Then
MsgBox "This record contains no data." _
, vbInformation, "Invalid Action"
Exit Sub
Else
strProductID = "rptProduction"
DoCmd.OpenReport strProductID, acViewPreview, , "[ID_1]='" & Forms!
frmProduction![ProductID] & "' And [OrderNo] = " & Forms!frmProduction!
[OrderNo]
DoCmd.PrintOut , , , , [OrderQty], 0


End If

Duane said:
Where do you expect OrderQty to come from? Do you have a control on your form
with the code named OrderQty?
I am trying to print a report depending on a the field "OrderQty". i did
created the code with the print command and the criteria and it looks like
[quoted text clipped - 12 lines]
going wrong with this.
--
 
G

Guest

I will reply in your previous thread with the same question.
--
Duane Hookom
Microsoft Access MVP


bigwillno2 via AccessMonster.com said:
Thanks for responding Duane,

OrderQty comes from Query named qrProduction and same query is the row source
of a multiselect list box on a form and OrderQty is also located in this list.
on the form, i have a cmd button that has the click even that carries the
printout proceedure. the source of the report that's being printed is also
the qrProduction. any thoughts? where am i going wrong?, it's this detailed
enough. the code is bellow,

Dim varItem As Variant 'Selected items
Dim strWhere As String 'String to use as WhereCondition
Dim strDescrip As String 'Description of WhereCondition
Dim lngLen As Long 'Length of string
Dim strDelim As String 'Delimiter for this field type.
Dim strDoc As String 'Name of report to open.
Dim strLabel As String
Dim prm_sched As Control
Dim DBS As Database
Dim rst As Recordset


Set prm_sched = Me![sched]

If prm_sched.ItemsSelected.Count = 0 Then
Beep
MsgBox "no item selected ", 48
Exit Sub
End If
Set DBS = CodeDb
Set rst = DBS.OpenRecordset("SELECT * FROM POhistory")

'run through all selected items
For Each varItem In prm_sched.ItemsSelected
rst.AddNew
rst!OrderNo = prm_sched.Column(0)
rst!RequiredDate = prm_sched.Column(1)
rst!CustomerID = prm_sched.Column(2)
rst!ModelNumber = prm_sched.Column(3)
rst!Description = prm_sched.Column(4)
rst!OrderQty = prm_sched.Column(5)
rst!Comment = prm_sched.Column(6)
rst!Bfill = prm_sched.Column(7)
rst!Qfill = prm_sched.Column(8)
rst!Uphfill = prm_sched.Column(9)
rst!Ptfill = prm_sched.Column(10)
rst!Spring = prm_sched.Column(11)
rst!Label = prm_sched.Column(12)
rst!Size = prm_sched.Column(13)
rst!Needle = prm_sched.Column(14)
rst!Pattern = prm_sched.Column(15)
rst!Config = prm_sched.Column(16)
rst!Border = prm_sched.Column(17)
rst!Border = prm_sched.Column(18)
rst!FoamCore = prm_sched.Column(19)
rst!FoamEnc = prm_sched.Column(20)
rst.update
Next
' strDelim = "" 'Delimiter appropriate to field type. See note 1.

strDoc = "rptProduction"
strLabel = "rptProductionLabel"
'Loop through the ItemsSelected in the list box.
If Me.sched.ItemsSelected.Count = 0 Then
Beep
MsgBox "no item selected ", 48
Exit Sub
End If
With Me.sched
For Each varItem In .ItemsSelected
If Not IsNull(varItem) Then
'Build up the filter from the bound column (hidden).
strWhere = strWhere & strDelim & .ItemData(varItem) &
strDelim & ","
'Build up the description from the text in the visible column.
See note 2.
'strDescrip = strDescrip & """" & .Column(1, varItem) & """,
"
End If
Next
End With

'Remove trailing comma. Add field name, IN operator, and brackets.
lngLen = Len(strWhere) - 1
If lngLen > 0 Then
strWhere = "[OrderNo] IN (" & Left$(strWhere, lngLen) & ")"
lngLen = Len(strDescrip) - 4
If lngLen > 0 Then
'strDescrip = "Production Required: " & Left$(strDescrip, lngLen)
End If
End If
'Report will not filter if open, so close it. For Access 97, see note 3.
If CurrentProject.AllReports(strDoc).IsLoaded Then
DoCmd.close acReport, strDoc
End If
'Omit the last argument for Access 2000 and earlier. See note 4.
DoCmd.OpenReport "rptProduction", acViewPreview, WhereCondition:=strWhere,
OpenArgs:=strDescrip
DoCmd.PrintOut , , , , [OrderQty]

i also tried it with this code bellow that doesnt have the strWhere and it
gives me the same error
Dim strProductID As String
Dim strCriteriaProductID As String
Dim strCriteriaOrderNo As String

If NewRecord Then
MsgBox "This record contains no data." _
, vbInformation, "Invalid Action"
Exit Sub
Else
strProductID = "rptProduction"
DoCmd.OpenReport strProductID, acViewPreview, , "[ID_1]='" & Forms!
frmProduction![ProductID] & "' And [OrderNo] = " & Forms!frmProduction!
[OrderNo]
DoCmd.PrintOut , , , , [OrderQty], 0


End If

Duane said:
Where do you expect OrderQty to come from? Do you have a control on your form
with the code named OrderQty?
I am trying to print a report depending on a the field "OrderQty". i did
created the code with the print command and the criteria and it looks like
[quoted text clipped - 12 lines]
going wrong with this.
--
 

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