Results 1 to 5 of 5
  1. #1
    MGF23 is offline Novice
    Windows 8 Access 2013 32bit
    Join Date
    Jan 2018
    Posts
    5

    where statement, macro tools, main and subform

    Hi guys



    I have a main form and a sub form linked by a 1 to many relationship. The field NC ref # number is the PK on the ‘main form’ and the FK in my other table on which my ‘subform’ is based.

    When I place a subform on the main table both NC ref#'s relate/sync to each other - which is what i want.

    Now I want to remove the sub form (from the main form) and put a command button in its place.

    I’ve used the wizard to put the button on the main form and open up this subform.

    Can anyone suggest a where statement I can use in macro tools to make sure NC REF# on main form matches NCR Ref# on the sub form each time the control button is clicked.

    Currently (for example) i could be on record: NC REF #20 - click the button and the subform shows NC ref#1.

    hope that is not too cryptic!

    Many thanks!

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    Just leave the subform alone. Make it invisible.
    then when the button is clicked , subform.visible = true

    no linking needed.

  3. #3
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I don't use macros... ever.

    BTW, "NC ref #" is an extreamly poor field name. It has spaces in the name and a special character (which happens to be a date delimiter).
    Better would be "NC_RefID_PK" for the primary key and "NC_RefID_FK" for the foreign key field.

    In VBA, it would be something like this:
    Code:
    Private Sub btnOpenSubForm_Click()
    
        DoCmd.OpenForm "MySubForm", , , "[NC_RefID_FK] = " & Me.NC_RefID_PK
    
    End Sub
    Change "MySubForm" to the name of your sub form.
    "btnOpenSubForm" is what I named the button.

    The macro *might* be like this (again, I never use macros, so this couold be way off):
    Click image for larger version. 

Name:	ButtonMacro1.png 
Views:	8 
Size:	23.6 KB 
ID:	32440

  4. #4
    MGF23 is offline Novice
    Windows 8 Access 2013 32bit
    Join Date
    Jan 2018
    Posts
    5
    Thanks for the response folks. I solved this one late last night via the VBA route. Great tip about the field name Steve. I've changed that now - that was me being lazy with 'short-handing' the word 'number'.

  5. #5
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    At one point I used names like "NC_RefNo". That was not real clear, so I switched to "NC_RefNum".

    I use "conserving energy" instead of "lazy"


    Happy you solved the problem.....

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

Similar Threads

  1. Replies: 10
    Last Post: 07-05-2017, 11:31 AM
  2. Replies: 1
    Last Post: 11-04-2015, 07:25 AM
  3. Replies: 3
    Last Post: 02-15-2013, 03:36 PM
  4. Main Form If Statement
    By qbc in forum Forms
    Replies: 1
    Last Post: 01-21-2012, 05:27 PM
  5. Replies: 3
    Last Post: 10-16-2009, 07:54 AM

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