Results 1 to 8 of 8
  1. #1
    gwboolean is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2012
    Posts
    65

    Wrong record selected from macro of an open form button

    This has been a recurring problem I have had. I have a parent form showing some of the contents of a single record in a parent table. This form contains a button that opens a specific subform (using an IF statement based on the contents of another field in the parent table/form. There are actually any of 8 child forms/tables that could be selected and the related record is in only one of them. The relation between the tables is based on the PK of the parent table and the related FK in the child table. and the data is correct in all tables.

    My problem is that when I run this button on the parent form/table it returns the appropriate form/table, but displays the first record rather than the related record. In the past (using this same process) I have been successful in getting to the right record by fiddling with the where statement (sometimes putting in a equal sign or taking it out fixes the problem). However, I have no idea what is taking place and this time no matter what I do to the Where statement nothing works. I have not yet placed the final else condition for where the form selection field (VMValIdentType] is empty yet as there is no point at this time.

    Here are the button macro contents:

    If [VMValIdentType] = "Software"

    OpenForm
    Form Name: tmpVMValSW
    View: Form
    Filter Name:
    Where Condition =: "[MBIDPK]="&"'"& [MBIDFK] &"'"
    Data Mode:
    Window Mode: Normal

    Else IF [VMValIdentType] = "Another Variable" There are 8 of these

    EndIF

    I would just be happy if I had an idea of what I was doing when I am doing this so that in the future I might be able to keep this problem from occurring. I do understand what is supposed to happen, but obviously just enough to be dangerous.
    Last edited by gwboolean; 05-01-2012 at 10:13 AM. Reason: incorrect spelling

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I would use code, the syntax of which is:

    BaldyWeb wherecondition

    In a macro, I think that you have to use the full form reference:

    Where Condition =: "[MBIDPK]='" & Forms!FormName.[MBIDFK] & "'"
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    gwboolean is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2012
    Posts
    65
    I gave that a try by changing [MBIDFK] to Forms![tmpVMValSW].[MBIDFK]. Same result. The contents of the first record are displayed on the correct form/table. Any other ideas? And I do know John Galt.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    One of the many reasons I don't use macros is they are harder to debug (I haven't used 2010 macros enough to know if that version is better in that regard). You'd want to confirm that the control with that name contains the value expect. If it's a combo, it may not. Can you post the db here?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    gwboolean is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2012
    Posts
    65
    I have no idea how to post a DB, I can barely navigate through all this. My experience with DBs pretty well stopped in 1994 with Foxbase. I have recently been working to be able to work with OBJ oreiented and am still just figuring out what I am doing.

    Having said that, I have setup both forms so that they show the fields that I am using to show what is actually there. Additionally, I have the tables open and can see that the fields of both tables contain the correct data. There are currently two records in the child table and each has the correct number in the field. MBIFK for one record is 26 and the MBIFK for the desired record is 27. When I look at the filter in the property values (after I take the parent form and put it in the design view, the filter in the property shows the appropriate number (27). It occurs to me though that this field is a number field and I seem to be treating everything as if it is a text value. Is there any chance that, that might be the source of my problem? Oh, and the button is not a combo, it is just a button that I have set the imbedded macro event to operate from an IF statement that defines which child/form table should be used.

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    If the data type of MBIDPK is numeric, try

    Where Condition =: "[MBIDPK]=" & Forms!FormName.[MBIDFK]

    To post a db here, you would perform a compact/repair, zip it and then attach in the Advanced Reply area.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    gwboolean is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2012
    Posts
    65
    That looks like it would require a new thread. Is that OK?

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    It's okay, but it shouldn't be required. Just click on "Go Advanced" under the quick reply area. Then you should see a "Manage Attachments" button.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 11
    Last Post: 01-26-2012, 01:22 PM
  2. Macro to open URL from Field record
    By COiSman in forum Programming
    Replies: 3
    Last Post: 12-26-2011, 02:25 PM
  3. Replies: 1
    Last Post: 03-31-2011, 12:18 PM
  4. Replies: 3
    Last Post: 01-14-2010, 08:32 AM
  5. Replies: 3
    Last Post: 10-16-2009, 07:54 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