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    
post Nov 28 2017, 12:41 PM

Posts: 1,191
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
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

Posts: 5,563
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.

Go to the top of the page
post Nov 28 2017, 01:23 PM

UtterAccess VIP
Posts: 10,186
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.
Go to the top of the page

Custom Search
RSSSearch   Top   Lo-Fi    23rd October 2018 - 05:28 PM