Solved

how to use VB string to populate a report

Posted on 2011-02-18
15
388 Views
Last Modified: 2012-05-11
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",acviewpreview, wherecondition:=str_full_string_single

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_SQLString_Single

End Sub


My thinking is that it's not using the string because the string is created under a different sub...  
Thoughts?
Brian
0
Comment
Question by:KollBrian
  • 9
  • 6
15 Comments
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 34928866
post the content of  the string "str_FULL_SQLString_Single"


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_SQLString_Single

End Sub
0
 

Author Comment

by:KollBrian
ID: 34929095
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]![Pallet_ID]='' Or [tbl_Box_Detail]![Pallet_ID] Is Null),[tbl_Box_Detail]![Venue_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_ID = 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
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 34929224
what is the RecordSource of the report..
0
 

Author Comment

by:KollBrian
ID: 34929394
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
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 34929414
are you going to use all the 4 combo boxes to filter the report?
0
 

Author Comment

by:KollBrian
ID: 34929718
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
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 34929729
upload a copy of the db
0
Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

 

Author Comment

by:KollBrian
ID: 34929854
ok :)

there is no real data yet, as I continue to work out the little bugs brian-db.accdb
0
 

Author Comment

by:KollBrian
ID: 34929924
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.
0
 

Author Comment

by:KollBrian
ID: 34930108
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...

0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 34930350
test this

codes added in between '***

select an item from cmb_boxid, then click
cmd_Search
brian-db.accdb
0
 

Author Comment

by:KollBrian
ID: 34942013
Hi Capricorn,

Same behavior, it still doesnt bring up the print preview.  

Brian
0
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
ID: 34943017
brian,

did you use/test the db i uploaded?

select an item from cmb_boxid, then click
cmd_Search
0
 

Author Comment

by:KollBrian
ID: 34944157
:( 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
0
 

Author Comment

by:KollBrian
ID: 34944977
It looks like I was guilty of "over thinking" this again.  I just ran "[tbl_Pallet_Detail]![Pallet_Req]=True And [tbl_Pallet_Detail]![Req_Printed]=False" 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...?
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now