Passing a variable from VB6 to Access
I'm sure this has been asked before, but couldn't find an answer using the search. What I need is to pass a varable from an inputbox to an access report, but not use it as a "where clause". The record I'll be printing should not be dependant on the value I enter, I just need that value in the corresponding place. The name of the Access report control is "periodche", the inputbox I'll be using is called "periodinp". I guess it will be something similar to this:
vb Code:
.DoCmd.OpenReport "kvit_plat_mqsto", acPreview, WhereCondition:="[periodche] = " & periodinp
but as I said, it should not be a where clause and I can't make it up. Thanks in advance!
I'm using Visual Basic 6 and Microsoft Access 2002.
Re: Passing a variable from VB6 to Access
Try this:
vb Code:
DoCmd.OpenReport "kvit_plat_mqsto", acPreview, ,"[periodche] = '" & periodinp & "'"
Re: Passing a variable from VB6 to Access
BTW take a look at this LINK
Re: Passing a variable from VB6 to Access
Now it gets the variable but I also get a parametre prompt from Access, where I also need to enter the value. Seems I messed up the report in Access itself, as when I start it from access it also asks for the parametre. I know it's (probably) not the right forum to ask this, but can I get a little help with Access? The control I'm trying to send the variable has "name" = "periodche" and as it doesn't get the value from any of the table fields, I deleted the control source. Any additional configuring of that text box?
I also took a look of the link you gave and I'm a little worried. Maybe I'm misunderstanding it, but does this:
Quote:
WhereCondition optional string expression that's a valid SQL WHERE clause without the keyword WHERE.
mean that only a WhereCondition can be placed here? As I previously said, I don't need a where clause, just to send the value to that textbox in the report. Hope I was able to express clearly, as I'm a bit confused atm.
Edit: Just realised that using the integrated access prompt would work if I'm able to make it a bit better looking. Any ideas how to change the "enter parameter value" title and the "periodche" "subtitle"?
Sorry for asking way offtopic questions, but I think it would be faster that way:blush:
Re: Passing a variable from VB6 to Access
Quote:
Originally Posted by veseo
. . . just to send the value to that textbox in the report. Hope I was able to express clearly, as I'm a bit confused atm.:
Are you trying to take the value from the TextBox and use it in a control on the Access Report or do you want to filter the data based upon that value?:confused:
Re: Passing a variable from VB6 to Access
I want to take the value and put it as the value of one of the fields in the Access Report, NOT to filter the data. Here's the whole deal:
I have a database of something you rent, with quite a lot of details, which details I put in the Report, getting them from the database. There's one other field, which needs to be also put in the report (and printed after that), whose value shows the length of the rent (1 month, 6 months, etc). I don't need to filter anything, neither do I need to put it into the database. I just need that value to be entered from that inputbox and then assigned to the Report textbox, called "periodche".
Re: Passing a variable from VB6 to Access
Re: Passing a variable from VB6 to Access
I tried with both of these ideas:
vb Code:
rpt.InputParameters = "@periodche= Int" &
Forms!form_karta_show!periodmsg
and
vb Code:
rpt.InputParameters = "@periodche Int=" & periodmsg
.
The first one results in "Run-time error '13' - Type mismatch", while the second one results in "run-time error '2455' - You entered an expression that has an invalid reference to the property InputParameters.".
I tried changing to VarChar, no goodie, the errors remain the same. Here's the code of the whole segment:
vb Code:
periodmsg = InputBox("Çà êàêúâ ïåðèîä å ïëàòåíî?", "Ïåðèîä íà ïëàùàíå")
Set objaccess = CreateObject("Access.Application")
With objaccess
.OpenCurrentDatabase filepath:="c:/db1.mdb"
.DoCmd.OpenReport "kvit_rep_ab", acViewDesign
Set rpt = .Reports("kvit_rep_ab")
'rpt.InputParameters = "@periodche VarChar=" & Forms!form_karta_show!periodmsg
rpt.InputParameters = "@periodche Int=" & periodmsg
.DoCmd.OpenReport "kvit_rep_ab", acPreview
.Visible = True
.DoCmd.Maximize 'maximizes the Report window
.DoCmd.Maximize 'maximizes Access window
End With
:ehh:
Note: the name of the report is not a mistake, it was mistaken in the first post of mine.
Edit: I noticed that I add a reference to Microsoft Access 10.0 Object Library (which I googled to be required for dim-ing as Access.Report), DoCmd.OpenReport doesn't seem to work anymore. Removing the reference fixes the problem.
Edit2: I decided to stick with the integrated Access Prompts. Question put on hold for now:p