Page 1 of 2 12 LastLast
Results 1 to 15 of 30
  1. #1
    bpepper82 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2014
    Posts
    14

    Problem opening form to a specific record from subform

    I have a form that displays details for a specific asset and a continuous
    subform that lists all the purchases for that asset. I have the following code
    in the On Click event for one of the fields in the subform:

    Dim myOrder
    As Integer
    myOrder = Me.txtOrder


    DoCmd.OpenForm "frmOrders", acNormal, ,
    "OrderID=" & myOrder, acFormEdit, , "Edit"

    The problem is, when I click
    on any item in the subform, the code returns the value of the first item in the
    form rather than the one clicked on. If I open the subform on its own (outside
    the main form) then the code works fine. I can't figure out why it won't work in
    a subform.

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    If OrderID is a text value then you will need your WhereCondition argument to be: "OrderID='" & myOrder & "'"

  3. #3
    bpepper82 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2014
    Posts
    14
    Quote Originally Posted by RuralGuy View Post
    If OrderID is a text value then you will need your WhereCondition argument to be: "OrderID='" & myOrder & "'"
    OrderID is an integer. I as habit label all my text boxes starting with txt.

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    What you described in the first post is a WhereCondition that has no valid match. It is as if it is an invalid WhereCondition.

  5. #5
    bpepper82 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2014
    Posts
    14
    Quote Originally Posted by RuralGuy View Post
    What you described in the first post is a WhereCondition that has no valid match. It is as if it is an invalid WhereCondition.
    It is picking up the value from txtOrder, but rather than picking up the value for the line in the subform that I click on, it is picking up the value for the first line displayed in the subform. If I open the subform on its own, then it works correctly. It's only not working when opened as a subform.

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Assuming your SubForm is in Continuous View mode, The current record changes when you move the focus on the SubForm by simply selecting another record. The Me.txtOrder "should" use the value of that control on the current record. The current record *will* change before the Click event code you posted unless you are doing something else. Add some msgboxes to the events so you can see what is really happening. Either that or single step the code.

  7. #7
    bpepper82 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2014
    Posts
    14
    Quote Originally Posted by RuralGuy View Post
    Assuming your SubForm is in Continuous View mode, The current record changes when you move the focus on the SubForm by simply selecting another record. The Me.txtOrder "should" use the value of that control on the current record. The current record *will* change before the Click event code you posted unless you are doing something else. Add some msgboxes to the events so you can see what is really happening. Either that or single step the code.
    Thanks for answering so quickly. I do have the SubForm in continuous view. I've done the message box thing and single stepped the code, and both tell me that it is picking up the first record regardless of which one I click on. Those lines execute and then the form opens, nothing else is happening in between.

  8. #8
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Comment out the openform code and just use a MsgBox to display the Me.OrderID value. Does it change each time you select a different record in the SubForm?

  9. #9
    bpepper82 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2014
    Posts
    14
    Quote Originally Posted by RuralGuy View Post
    Comment out the openform code and just use a MsgBox to display the Me.OrderID value. Does it change each time you select a different record in the SubForm?
    Yes, every one I click on gives the value for the first record.

  10. #10
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Is your code in the SubForm? How about is you select a different control in the SubForm 1st and then the one with the code?

  11. #11
    bpepper82 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2014
    Posts
    14
    Quote Originally Posted by RuralGuy View Post
    Is your code in the SubForm? How about is you select a different control in the SubForm 1st and then the one with the code?
    My code is in the subform. I just tried selecting another control first and got the same result.

  12. #12
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Try importing your db into a fresh new db and see if the problem follows. It only takes a minute: http://www.btabdevelopment.com/ts/impnew

  13. #13
    bpepper82 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2014
    Posts
    14
    Quote Originally Posted by RuralGuy View Post
    Try importing your db into a fresh new db and see if the problem follows. It only takes a minute: http://www.btabdevelopment.com/ts/impnew
    Unfortunately the problem does persist

  14. #14
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Do you have the SubForm locked or something? It is not changing the Current Record and that is not right. Can you post your db maybe? Remove any sensitive data of course.

    I did notice you were passing the word "Edit" to the next form in the OpenArgs argument. Could it be something you are doing in the OnLoad or Open event of the next form?
    Last edited by June7; 01-28-2014 at 07:49 PM.

  15. #15
    bpepper82 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2014
    Posts
    14
    Quote Originally Posted by RuralGuy View Post
    Do you have the SubForm locked or something? It is not changing the Current Record and that is not right. Can you post your db maybe? Remove any sensitive data of course.

    I did notice you were passing the word "Edit" to the next form in the OpenArgs argument. Could it be something you are doing in the OnLoad or Open event of the next form?
    I cannot upload the db unfortunately. One of those things working for a bank, they are very strict on security. I don't think it has anything to do with the OnLoad event on the form that opens, because I can isolate the problem to the OnClick event in the subform. I did just confirm that the subform is not locked.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 12-13-2013, 04:50 PM
  2. Replies: 9
    Last Post: 10-09-2013, 08:45 AM
  3. Opening Form to a Specific Record
    By PPat in forum Forms
    Replies: 9
    Last Post: 04-24-2013, 08:47 PM
  4. Help with opening form to specific record
    By manic in forum Programming
    Replies: 7
    Last Post: 09-18-2012, 08:44 PM
  5. Replies: 1
    Last Post: 11-09-2010, 03:02 PM

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