Results 1 to 11 of 11
  1. #1
    accesscoder is offline Novice
    Windows Vista Access 2007
    Join Date
    Sep 2010
    Posts
    19

    Passing parameter between form and corresponding popup form

    Hello,

    I am creating a form with unbound 'patientID' textbox. Internally I am checking if the patient information for the 'patientID' entered by user is already present in the patient table. If that patientID is not present in the patient table then I am opening a new pop-up form, where I am allowing user to fill the patient information. Here I want to pass the patientId from 'patientId' text box on the main form to the 'patientId' text box in the pop-up form. How can I achieve this?

    I highly appreciate your help!

  2. #2
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    the open args is sometimes difficult to interpret.

    What you might want to do instead is use DCOUNT() to determine if the id is in the table, and then if it's not, open the form in Data Entry mode and use direct referencing to populate the id for the new record from the previous form (provided it's still open).

  3. #3
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    I would use a ComboBox and the NotInList event for what you are suggesting, but that's just me.

  4. #4
    DaveT is offline Access Developer
    Windows 7 Access 2010 (version 14.0)
    Join Date
    May 2010
    Location
    Texas
    Posts
    69
    If you're going to open the new form as a dialog, requiring the user to process the form (new patient), then I would use OpenArgs such as:

    DoCmd.OpenForm "myForm", , , , , acDialog, myNewPatientID

    For myForm, OnOpen:

    If Len(Nz(Me.OpenArgs)) > ZERO Then
    myFieldPatientID = Me.OpenArgs
    End IF

    As always, there's more than one way to program solutions and sometimes it's a matter of personal preference.

  5. #5
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Quote Originally Posted by DaveT View Post
    If you're going to open the new form as a dialog, requiring the user to process the form (new patient), then I would use OpenArgs such as:

    DoCmd.OpenForm "myForm", , , , , acDialog, myNewPatientID

    For myForm, OnOpen:

    If Len(Nz(Me.OpenArgs)) > ZERO Then
    myFieldPatientID = Me.OpenArgs
    End IF
    That looks like something that is in the help article Dave. I personally have never cared for Open Args because it requires code behind both objects, whereas the Where clause in the argument section can do it alone.

    Is there any effeciency difference between the two?

  6. #6
    DaveT is offline Access Developer
    Windows 7 Access 2010 (version 14.0)
    Join Date
    May 2010
    Location
    Texas
    Posts
    69
    The code snippet is an edited version from one of my apps. I use OpenArgs all the time, when it's appropriate. Often I may be calling the form (or report) from different contexts, in which case I may use a Select Case statement and take action accordingly.

    As I read the question, it was not a select/filter issue but a plug a value question to use in creating a new record.

    Of course, in my case, I typically add new records from unbound forms, check that the data is OK, then use DAO to save the record, go back to a more complete form (maybe using Where, maybe using a global and query) for completing the new record with all the non-required fields.

    I might also OpenArgs to open a form and set a combo value, etc.

    I didn't go into that approach here because I felt it off the subject.

    In most of these cases, I don't feel there's a right or wrong answer: just what works/doesn't work, is reliable, and can be deciphered by the next programmer who has to support the app.

  7. #7
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Quote Originally Posted by ajetrumpet View Post
    I personally have never cared for Open Args because it requires code behind both objects, whereas the Where clause in the argument section can do it alone.
    ...and as you have noticed, I try and suggest code wherever I can. Learning VBA opens up an almost limitless area of Access that enables developers to do some really amazing things. Avoiding code really hampers what can be achieved in Access.

  8. #8
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Quote Originally Posted by RuralGuy View Post
    ...and as you have noticed, I try and suggest code wherever I can. Learning VBA opens up an almost limitless area of Access that enables developers to do some really amazing things. Avoiding code really hampers what can be achieved in Access.
    I'm aware. But on the other hand, IMO it is always good to use interface alternatives as opposed to coding when you're in a "novice" stage of developing.

    I have written some pretty radical things myself, and everytime I don't like doing it because the longer a procedure runs and the more complex it is, the greater the chance of corruption, especially on shared networks.

  9. #9
    NoellaG's Avatar
    NoellaG is offline VIP
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,035
    Hi,

    why not add a customerID property to the popup, and fill it after openening the form? I find working with custom made properties very rewarding. It's a shame Microsoft didn't add inheritance to it's forms. This way you could create your own super/mother forms with prewritten properties/methods. Now I'm stuck with search forms I have to copy each time.

    gr
    NG

  10. #10
    accesscoder is offline Novice
    Windows Vista Access 2007
    Join Date
    Sep 2010
    Posts
    19
    Thank you everybody, for your prompt reply!

    @ruralguy - I wanted to use the unbound combo box approach suggested by you, but later on thought what if patient id becomes very large, millions for example. Then it will not be very efficient to populate the combo box with millions of entries and it's not in the list event. That's why I used the unbound text box. Please let me know, if this is not the right approach.

    @ajetrumpet - I did not get what do you mean by the "direct referencing" in your following response. Can you please elaborate it?

    and use direct referencing to populate the id for the new record from the previous form (provided it's still open).
    Thank you for all your help!

  11. #11
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Quote Originally Posted by accesscoder View Post
    @ruralguy - I wanted to use the unbound combo box approach suggested by you, but later on thought what if patient id becomes very large, millions for example. Then it will not be very efficient to populate the combo box with millions of entries and it's not in the list event. That's why I used the unbound text box. Please let me know, if this is not the right approach.
    Any approach that works is a *good* approach. As for the "millions of entries" issue I would suggest this: http://allenbrowne.com/ser-32.html
    There a many ways to solve almost every issue in Access once using code is no longer an issue.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Form Help with passing records
    By mwabbe in forum Forms
    Replies: 6
    Last Post: 09-08-2010, 11:06 AM
  2. Replies: 0
    Last Post: 06-14-2010, 09:41 AM
  3. Form-Subform-Popup Problem
    By TrudyD1474 in forum Forms
    Replies: 1
    Last Post: 06-10-2010, 05:36 PM
  4. bypassing passing parameter when null
    By cowboy in forum Queries
    Replies: 11
    Last Post: 04-14-2010, 09:59 PM
  5. Passing current form name to other form
    By owiec in forum Forms
    Replies: 2
    Last Post: 11-15-2009, 05:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums