UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Unbound Form Textbox Data To Unbound Report Help, Access 2010    
 
   
wornout
post Nov 28 2017, 12:41 PM
Post#1



Posts: 972
Joined: 17-November 13
From: Orewa New Zealand


I have an unbound pop up form with 2 textboxs Hascompany and HasPartner. I want to be able to Type a Y for yes or N for No or leaver no blank and on the button click open my report "BlankTaxLetter" and put the data in to 2 textboxs on the report so I can reformat the report based on those answers.
I seem to be having trouble I am trying but it stops on DoCmd.OpenReport "BlankTaxLetter", acViewReport, , strSQL saying action requires a valid report name argument
CODE
Private Sub Command4_Click()

varHasPartner = Me.HasPartner
varHasCompany = Me.HasCompany

strSQL = "( varHasPartner ) AND (varHasCompany )"
DoCmd.OpenReport "BlankTaxLetter", acViewReport, , strSQL

End Sub


or is there another way to do this?
Go to the top of the page
 
tina t
post Nov 28 2017, 01:20 PM
Post#2



Posts: 5,197
Joined: 11-November 10
From: SoCal, USA


text values of "Y" and "N" are not boolean values - they're text. so, as an example, if you typed "Y" in textbox HasPartner and "N" in textbox HasCompany, then the literal value of the strSQL variable is

"( Y ) AND ( N )"

that won't filter anything. you're getting the error about an invalid argument because, well, the argument string is invalid.

first, recommend as a best practice that you declare all variables in your code. in fact, best practice is that you set the Option "Require Variable Declaration" to True (it's a checkbox, probably), so that all new modules you create in Access will do just that, going forward. (note that the setting has no effect on existing modules in any database; you should manually add the statement Option Explicit to the top of all existing modules and then compile the code and add missing declarations where needed.)

next, you need to construct a WHERE clause, without the keyword WHERE, of course. that's essentially what a filter string is. so a field in the report's Recordsource needs to match the value of the named form control. something like

strSQL = "FirstFieldname = '" & varHasPartner & "' And SecondFieldname = '" & varHasCompany & "'"

the above assumes that the variables will return valid text values. if you need them to return boolean values, then you're going to have to tweak your approach a bit.

hth
tina

--------------------
"you can't take the sky from me"
Go to the top of the page
 
projecttoday
post Nov 28 2017, 01:23 PM
Post#3


UtterAccess VIP
Posts: 8,683
Joined: 10-February 04
From: South Charleston, WV


Are you trying to format a report. If so, I think the most common ways to pass parameters are via the openargs on openreport and referencing the form fields directly in the report.
If you are trying to filter a report, then yes, you would go with the where condition.

--------------------
Robert Crouser

My company's website
Go to the top of the page
 


Custom Search
RSSSearch   Top   Lo-Fi    16th December 2017 - 09:48 AM