Results 1 to 8 of 8

Thread: Passing a variable from VB6 to Access

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2007
    Posts
    14

    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:
    1. .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.
    Last edited by veseo; Aug 28th, 2007 at 04:08 PM.

  2. #2
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: Passing a variable from VB6 to Access

    Try this:

    vb Code:
    1. DoCmd.OpenReport "kvit_plat_mqsto", acPreview, ,"[periodche] = '" & periodinp & "'"
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  3. #3
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: Passing a variable from VB6 to Access

    BTW take a look at this LINK
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  4. #4

    Thread Starter
    New Member
    Join Date
    Aug 2007
    Posts
    14

    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:
    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
    Last edited by veseo; Aug 28th, 2007 at 04:22 PM.

  5. #5
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    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?
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  6. #6

    Thread Starter
    New Member
    Join Date
    Aug 2007
    Posts
    14

    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".

  7. #7
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: Passing a variable from VB6 to Access

    Take a look at this LINK
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  8. #8

    Thread Starter
    New Member
    Join Date
    Aug 2007
    Posts
    14

    Re: Passing a variable from VB6 to Access

    I tried with both of these ideas:
    vb Code:
    1. rpt.InputParameters = "@periodche= Int" &
    2. Forms!form_karta_show!periodmsg

    and

    vb Code:
    1. 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:
    1. periodmsg = InputBox("Çà êàêúâ ïåðèîä å ïëàòåíî?", "Ïåðèîä íà ïëàùàíå")
    2. Set objaccess = CreateObject("Access.Application")
    3. With objaccess
    4.         .OpenCurrentDatabase filepath:="c:/db1.mdb"
    5.         .DoCmd.OpenReport "kvit_rep_ab", acViewDesign
    6.         Set rpt = .Reports("kvit_rep_ab")
    7.         'rpt.InputParameters = "@periodche VarChar=" & Forms!form_karta_show!periodmsg
    8.         rpt.InputParameters = "@periodche Int=" & periodmsg
    9.        .DoCmd.OpenReport "kvit_rep_ab", acPreview
    10.  
    11.             .Visible = True
    12.  
    13.             .DoCmd.Maximize 'maximizes the Report window
    14.  
    15.             .DoCmd.Maximize 'maximizes Access window
    16. End With


    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
    Last edited by veseo; Aug 29th, 2007 at 09:43 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width