[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Access VBA Query Parameter

Posted on 2010-08-27
7
Medium Priority
?
673 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 2000 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Suggested Courses

656 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