Solved

Access VBA Query Parameter

Posted on 2010-08-27
7
662 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
  • 4
  • 3
7 Comments
 
LVL 5

Expert Comment

by:INHOUSERES
Comment Utility
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
Comment Utility
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
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:mcs26
Comment Utility
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
Comment Utility
I should also say the txtISIN is populates with the correct value
0
 

Author Comment

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

Expert Comment

by:INHOUSERES
Comment Utility
Ah yes, sorry for omitting that.

Glad I could have been of assistance.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now