Solved

Access VBA Query Parameter

Posted on 2010-08-27
7
663 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
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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

776 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