Solved

Access VBA Query Parameter

Posted on 2010-08-27
7
666 Views
Last Modified: 2013-11-28
Hi,

I have an form called frmMain and I have a subform which is as query. The query ask the user to enter a parameter and the form opens fine.

My question is how can I open this form via vba and pass the parameter value into the query so it loads up like it would as above? I'm using Access 2000 and I cannot use the OpenQueryDefs method.

Thanks,



0
Comment
Question by:mcs26
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 5

Expert Comment

by:INHOUSERES
ID: 33540705
myVariable = "Hello World"
docmd.OpenForm "testForm",,,,,,myVariable

In the form, you can reference that viariable via "Me.OpenArgs":

msgbox me.OpenArgs
0
 

Author Comment

by:mcs26
ID: 33540727
Hi INHouseres,

Thanks for the reply. I have just tried the code below. The only problem is when the form opens up the query parameter still asks me to enter the variable?

Thanks

Sub PriceChecksUpdate()

Dim ISIN As String

    ISIN = InputBox("Please enter bonds ISIN:", "ISIN")
    DoCmd.OpenForm "frmPriceUpdate", acNormal, , , , , ISIN

End Sub
0
 
LVL 5

Accepted Solution

by:
INHOUSERES earned 500 total points
ID: 33540745
Sorry, I've slightly missunderstood your question.

On the form, create a new text box called "txtISIN"
When the form opens, put the OpenArgs into the textbox:
txtISIN = Me.OpenArgs

If the query has a filter which opens a parameter [Please Enter Bonds ISIN], you should then change this to:

Forms!frmPriceUpdate!txtISIN

Hope this works!

0
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 

Author Comment

by:mcs26
ID: 33540861
Thanks for that. I have added a text box however when the form loads up the query does not return any records.

In my query I have in the criteria box [Forms]![frmPriceUpdate]![txtISIN].

The code I have is below, thanks again!

Sub PriceChecksUpdate()

Dim ISIN As String

    ISIN = InputBox("Please enter bonds ISIN:", "ISIN")
    DoCmd.OpenForm "frmPriceUpdate", acNormal, , , , , ISIN

End Sub

In the form I have

Private Sub Form_Load()
    Me.txtISIN = Me.OpenArgs
End Sub
0
 

Author Comment

by:mcs26
ID: 33540890
I should also say the txtISIN is populates with the correct value
0
 

Author Comment

by:mcs26
ID: 33540898
I just added me.recalc & its now works thanks very much
0
 
LVL 5

Expert Comment

by:INHOUSERES
ID: 33541128
Ah yes, sorry for omitting that.

Glad I could have been of assistance.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

726 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