Results 1 to 3 of 3
  1. #1
    websterh is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2010
    Posts
    8

    Exclamation Open (sub)form linking 2 criteria on current form

    Hi, THIS IS AN URGENT POSTING (it's for work)

    Sorry if this sounds repetitive but i have searched on the internet and other forums for for at least 4 hours to find a clear answer to this but when i try those steps "Type mismatch" and other error messages always appear.

    Table structure:
    Primary Key = MRN
    Primary Key = Facility (due to facilities possibly having the same MRN)

    I have one form (CLIENT) that holds/displays the main information.
    I click on a button to open the popup form (CLIENT Edit).


    I am wanting to open this form linking the active record (on CLIENT) to the opened record (on CLIENT Edit) using both the MRN & Facility references.

    The following works for the first MRN matching the criteria:
    DoCmd.OpenForm "CLIENT Edit", acNormal, , "[MRN]=" & Me.[MRN], acFormEdit, acWindowNormal
    This however only gets the first Facility name (sorted A-Z) instead of the actual record i would like. Example: MRN 001231 are both at HosA and HosT; whenever the button is clicked HosA will always appear when it loads even though HosT is the record/facility i want.

    Any chance someone could please post the VBA to this as i have tried roughy 20 different variations of possibly workarounds/answers but they do not seem to work?.

  2. #2
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    ...<snip>I am wanting to open this form linking the active record (on CLIENT) to the opened record (on CLIENT Edit) using both the MRN & Facility references.

    The following works for the first MRN matching the criteria:
    DoCmd.OpenForm "CLIENT Edit", acNormal, , "[MRN]=" & Me.[MRN], acFormEdit, acWindowNormal
    This however only gets the first Facility name (sorted A-Z) instead of the actual record i would like. Example: MRN 001231 are both at HosA and HosT; whenever the button is clicked HosA will always appear when it loads even though HosT is the record/facility i want.

    Any chance someone could please post the VBA to this as i have tried roughy 20 different variations of possibly workarounds/answers but they do not seem to work?.
    At the beginning of the procedure add:

    Code:
       Dim strWhere as String
    then

    Code:
    ' If the field "[Facility]" is a string, use delimiters
    strWhere = "[MRN]=" & Me.[MRN] & " and [Facility] = '" & Me.TEXT_BOX_NAME & "'"
    DoCmd.OpenForm "CLIENT Edit", acNormal, , strWhere, acFormEdit, acWindowNormal


    where
    "Me.TEXT_BOX_NAME" is the name of the control the has the Facility name. Change "Me.TEXT_BOX_NAME" to the name of your control.

    If you set a breakpoint, you can check strWhere to see if the "Where" string has the correct parameters.

  3. #3
    websterh is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2010
    Posts
    8

    Talking

    Thank you so much for the quick reply (and great coding) Steve.

    It works.
    For everyone's reference the coding is below.

    Private Sub CMD2ClientEdit_Click()
    Dim strWhere As String
    strWhere = "[MRN]=" & Me.[MRN] & " and [Facility] = '" & Me.[Facility] & "'"
    DoCmd.OpenForm "CLIENT Edit", acNormal, , strWhere, acFormEdit, acWindowNormal
    End Sub
    I seemed to have the strWhere and the single quote, i.e. ' , missing but... yay --- this has def been the highlight of my day.
    Last edited by websterh; 02-08-2011 at 12:04 AM. Reason: formatting of [ ] in vba

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

Similar Threads

  1. Replies: 63
    Last Post: 01-25-2013, 05:20 AM
  2. Replies: 2
    Last Post: 02-26-2010, 08:14 AM
  3. Passing current form name to other form
    By owiec in forum Forms
    Replies: 2
    Last Post: 11-15-2009, 05:50 AM
  4. Open form to current record
    By rbpd5015 in forum Access
    Replies: 1
    Last Post: 08-28-2009, 01:53 AM
  5. Open form based on Subform criteria
    By Suzan in forum Programming
    Replies: 0
    Last Post: 04-25-2006, 02:28 PM

Tags for this Thread

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