Solved

ms access me.openargs in form record source

Posted on 2015-02-01
1
708 Views
Last Modified: 2016-02-10
Hi,

I'm have created an application using ms access 2013 and having a little trouble passing a value from one form which is to be used in the query for another form. I can capture the value and by using me.openargs on the destination form populate a text box. Me.text41 = me.openargs. this works fine but I'm not sure how I can use the value in the record source query for the form. Do I need to set up a parameter in the record source query and somehow update that with the me.openargs value using VBA or can I reference the me.openargs value directly in a form record source query or is there a better way. The query for the form is quite long but basically I just need to pass a number which will be used ad the ID in the query

Thanks
0
Comment
Question by:victoriaharry
[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
1 Comment
 
LVL 48

Accepted Solution

by:
Dale Fye (Access MVP) earned 500 total points
ID: 40582461
Generally, when I want to open a form to a particular record, I use the WhereCondition argument of the OpenForm method.  This will take me to a record in another form, which I know exists.

docmd.OpenForm "formName", acNormal, [FilterName], [WhereCondition]

I generally build my WhereCondition as a separate string:

Dim strCriteria as string
strCriteria = "[ID] = " & me.txt_ID
docmd.OpenForm "formName", , , strCriteria, , acDialog

You can use the OpenArgs argument, but you will probably need more code than what you provide.  As an example, you might do something like:
Private Sub Form_Open(Cancel as Integer)

    Dim strCriteria as string

    strCriteria = "[ID] = " & me.OpenArgs

    With me.recordsetclone
        .FindFirst strCriteria
        if .nomatch then
            if msgbox("Not found, add record", vbOkCancel) = vbCancel Then
                 Cancel = true
                 Exit Sub
            else
                 docmd.GoToRecord , , acNewRec
                 me.Text41 = me.OpenArgs
            endif
       Else
            me.bookmark = .bookmark
       end if
   end with

End Sub

Open in new window

This subroutine, or something similar would open the form, attempt to locate the record where the [ID] field value is equal to the ID you passed to it.  If found, it would set the focus to that record.  If not found, it would prompt the user asking whether to add a new record.  If the user selects OK, it would go to a new record and assign the text41 control the value of the OpenArgs.  Otherwise, it would Cancel the form open event, returning control to the
docmd.openform line from the first form.
0

Featured Post

Independent Software Vendors: 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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
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…
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…

752 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