KollBrian
asked on
how to use VB string to populate a report
Hi,
I am down to my last command button function and my form will be complete :)
I have a command button that filters a sub_form based on the value from a combo box. The value in VB for that "Private Sub" is "str_FULL_SQLString_Single ".
I have also created a report from the sub form.
I am trying to program a button reading:
---docmd.openreport "rpt_Print_Single",acviewp review, wherecondition:=str_full_s tring_sing le
But when the report comes up, it is not using the filter setup in the string.
Private Sub cmd_Preview_Report_Click()
output:
DoCmd.OpenReport "rpt_test_print", acViewPreview, , wherecondition:=str_FULL_S QLString_S ingle
End Sub
My thinking is that it's not using the string because the string is created under a different sub...
Thoughts?
Brian
I am down to my last command button function and my form will be complete :)
I have a command button that filters a sub_form based on the value from a combo box. The value in VB for that "Private Sub" is "str_FULL_SQLString_Single
I have also created a report from the sub form.
I am trying to program a button reading:
---docmd.openreport "rpt_Print_Single",acviewp
But when the report comes up, it is not using the filter setup in the string.
Private Sub cmd_Preview_Report_Click()
output:
DoCmd.OpenReport "rpt_test_print", acViewPreview, , wherecondition:=str_FULL_S
End Sub
My thinking is that it's not using the string because the string is created under a different sub...
Thoughts?
Brian
ASKER
Hi Capricorn,
Same result, the report displays but has all the data.
When I run the "single search" command button, the SQL verbage is:
SELECT tbl_Box_Detail.[Box_ID], tbl_Box_Detail.[Pallet_ID] , tbl_Box_Detail.[Part_ID], tbl_Box_Detail.[Quantity], IIf(([tbl_Box_Detail]![Pal let_ID]='' Or [tbl_Box_Detail]![Pallet_I D] Is Null),[tbl_Box_Detail]![Ve nue_Ref],[ tbl_Pallet _Detail]![ Venue_Ref] ) AS Venue_Ref, tbl_box_detail.[box_req], tbl_pallet_detail.[pallet_ req] FROM tbl_Pallet_Detail RIGHT JOIN tbl_Box_Detail ON tbl_Pallet_Detail.Pallet_I D = tbl_Box_Detail.Pallet_ID WHERE part_id = 'Part #1'
Well the very last part after the Where is variable but you get the picture. But when I refer to this string in VB as the string name (str_full_sqlstring_single ) in the print command like you have in your sample all i get is the report, not a filtered report...
I also cleared the Immediate window on the VB screen when I ran your sample and nothing populated... not sure if thats related to the report filter or not.
Brian
Same result, the report displays but has all the data.
When I run the "single search" command button, the SQL verbage is:
SELECT tbl_Box_Detail.[Box_ID], tbl_Box_Detail.[Pallet_ID]
Well the very last part after the Where is variable but you get the picture. But when I refer to this string in VB as the string name (str_full_sqlstring_single
I also cleared the Immediate window on the VB screen when I ran your sample and nothing populated... not sure if thats related to the report filter or not.
Brian
what is the RecordSource of the report..
ASKER
Hi Capricorn,
The record source for the report is the same as the source for the sub-form:
qry_box_to_pallet_print
So, the main "search" form has the sub-form imbedded into it. When you use one of the 4 combo boxes to specify the value you want, the command buttons then goto work and create the string you saw above to alter the view of the sub-form to only show the requested info.
Brian
The record source for the report is the same as the source for the sub-form:
qry_box_to_pallet_print
So, the main "search" form has the sub-form imbedded into it. When you use one of the 4 combo boxes to specify the value you want, the command buttons then goto work and create the string you saw above to alter the view of the sub-form to only show the requested info.
Brian
are you going to use all the 4 combo boxes to filter the report?
ASKER
Yes and no, I have 2 command buttons, one is a single filter/search and one does a specific double (only 2 of the 4 combos).
I figured once I got the printing to work for the single, duplicating that for the double wouldnt be toooooooooo hard :)
Brian
I figured once I got the printing to work for the single, duplicating that for the double wouldnt be toooooooooo hard :)
Brian
upload a copy of the db
ASKER
ASKER
The button for single search is where i am currently tinkering, thats why it wont work at the moment, it is erroring due to the sql string being too long for the rpt where.
So I am tinkering to figure that out at the moment. The "preview report" button actually does work, just not with the filtered view... That was covered a little while ago when I figured out the string was empty...
My working theory is if I can get the single search to work with printing (and double down the way) I will duplicate single search and make it "single search print" and just have one that filters and one that prints. But I have to get the string to work first so... thats where I am at the moment. how to get a really long string to work in a report.
So I am tinkering to figure that out at the moment. The "preview report" button actually does work, just not with the filtered view... That was covered a little while ago when I figured out the string was empty...
My working theory is if I can get the single search to work with printing (and double down the way) I will duplicate single search and make it "single search print" and just have one that filters and one that prints. But I have to get the string to work first so... thats where I am at the moment. how to get a really long string to work in a report.
ASKER
I am now tinkering (i.e. researching) how to use the string to update the query and then run the report. I am thinking I was going down the wrong path...
test this
codes added in between '***
select an item from cmb_boxid, then click
cmd_Search
brian-db.accdb
codes added in between '***
select an item from cmb_boxid, then click
cmd_Search
brian-db.accdb
ASKER
Hi Capricorn,
Same behavior, it still doesnt bring up the print preview.
Brian
Same behavior, it still doesnt bring up the print preview.
Brian
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
:( oops apologies, I didnt realize the test fix was specific to the BoxID :)
Yes that works perfectly.
what I am seeing is you created a strfilter string. and that string replaces my "full single" string.
what I am having a hard time figuring is the IF clause in the combo box section of the VB. It reads like a sub if, so I did a test and copied it to all four combo boxes and it works for all but one, the venue ref combo box.
The VB doesnt really give an error it just goes to debug when trying to filter only venue ref... My guess is that I am still running into the "too long" problem with the report but when I try to copy/paste a string that does work into a test report macro button it still says too long so I am unsure, why would venue_ref fail but the others work.?
Brian
Yes that works perfectly.
what I am seeing is you created a strfilter string. and that string replaces my "full single" string.
what I am having a hard time figuring is the IF clause in the combo box section of the VB. It reads like a sub if, so I did a test and copied it to all four combo boxes and it works for all but one, the venue ref combo box.
The VB doesnt really give an error it just goes to debug when trying to filter only venue ref... My guess is that I am still running into the "too long" problem with the report but when I try to copy/paste a string that does work into a test report macro button it still says too long so I am unsure, why would venue_ref fail but the others work.?
Brian
ASKER
It looks like I was guilty of "over thinking" this again. I just ran "[tbl_Pallet_Detail]![Pall et_Req]=Tr ue And [tbl_Pallet_Detail]![Req_P rinted]=Fa lse" in a generic macro command button and viola it does the job I need it to do. :)
Capricorn Many thanks for you help, I would still like to know why the sub-if doesnt work on that one combo box though...?
Capricorn Many thanks for you help, I would still like to know why the sub-if doesnt work on that one combo box though...?
you can get it by adding this line before opening the report
Private Sub cmd_Preview_Report_Click()
output:
debug.print str_FULL_SQLString_Single
DoCmd.OpenReport "rpt_test_print", acViewPreview, , wherecondition:=str_FULL_S
End Sub