Solved

ms access me.openargs in form record source

Posted on 2015-02-01
1
679 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
1 Comment
 
LVL 47

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

792 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