Results 1 to 12 of 12
  1. #1
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    513

    updating a form based on the values of another (seperate) form


    I have 2 forms
    the primary form MUST be a continuous form
    on it is a command button to open a second form (if the user thinks it is necessary...)
    the second form is essentially a subform of the first that displays multiple records related to a field in the current record of the main, first form

    the 2nd opens with this code

    stDocName = "FrmManufacturerAddlCatagoryEntry"

    stLinkCriteria = "[ManufacturerName]=" & "'" & Me![txtManufacturerName] & "'"
    DoCmd.OpenForm stDocName, , , stLinkCriteria


    ----------------------t
    the problem is that when I change record focus on the first form, I can't get the data on the second to requery

    on the 1st form I have this code:
    Private Sub Form_Current()
    If (SysCmd(acSysCmdGetObjectState, acForm, "FrmManufacturerAddlCatagoryEntry") And acObjStateOpen) = acObjStateOpen Then
    With Forms![FrmManufacturerAddlCatagoryEntry].
    .[lblManufacturerName].Caption = Me.ManufacturerName
    .Requery
    .Repaint
    End With
    End If

    lblManufacturerName.Caption updates correctly, so I know I must be in the right area
    maybe?

    thoughts, and thanks in advance,
    Mark

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    The current record in the continuous form will be the record that has focus. If the control is in the header, you will lose focus. Try a dbl click event in the text box that is relevant to the user. Another option is to place a control in the detail section.

  3. #3
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    513
    the control is in the header, band the intent is that the user clicks it only once; the 2nd form opens, and stays open as they navigate thru the records of the 1st form.

    the intent is that when the focus of the 1st form changes to a different record, that the records in the 2nd form are update to be those where ManufacturerName (on the 2nd) = Me![txtManufacturerName] on the first.

    this is to say:
    it should behave just like a sub form on the first, but because I need to have the first as a continuous form, I cannot do... =:-(

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    I had to edit my post. If the control is in the header of the continuous form, the focus will be on the control and not on a specific record. So I do not see how even your stLinkCriteria is working to open the form.

    The current event will work. In order for it to fire, the user has to click within the record. This is why I suggest a double click or button. What are you using to encourage the user to set focus on the record within the continuous form?

  5. #5
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    I think I am starting to see....

    Looks like you are using an unbound textbox to pass the value of ManufacturerName to your stLinkCriteria.

    Here is the thing. When the second form opens, it is only going to show a portion of the records in the table or query. The where criteria is limiting the records in the recordset to this

    stLinkCriteria = "[ManufacturerName]=" & "'" & Me![txtManufacturerName] & "'"

    if the value of ManufacturerName changes, it will not be found in the second form's recordset. The second form's recordset is limited by the where criteria in the docmd.

    You would have to reassign the recordsource of the second form to the original SQL and apply the new where criteria as the focus changes within the first form.

    If you post the SQL for the original query without the Where clause, we can probably figure something out

  6. #6
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    513
    the control is in the header, and it does work (not experienced to know why... but it does)

    about the current event, you're right, it does work; I know this because the first line of code works spot-on (it the second, where I ask the form to requery, that doesn't work
    With Forms![FrmManufacturerAddlCatagoryEntry].
    .[lblManufacturerName].Caption = Me.ManufacturerName

    could this be because it's query is in its open statement, and as such, there is actually no query inherent in the form to "requery"?
    stLinkCriteria = "[ManufacturerName]=" & "'" & Me![txtManufacturerName] & "'"
    DoCmd.OpenForm stDocName, , , stLinkCriteria

    if this is the case...
    Do you thin if I add a criteria to the forms record set, that do the trick?
    =forms![FrmManufacturerAddlCatagoryEntry].[txtManufacturerName]

  7. #7
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    513
    well...
    I just tried that and it didn't work at all
    even when the 2nd form opened for the first time, its records weren't correctly filtered

  8. #8
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    Totally have to reassign the recordset to the second form. What is the second form based on? A query or a table? If it is a query, can you post the SQL?

  9. #9
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    513
    it is a table

    SELECT MfrCatagory.ManufacturerName, MfrCatagory.Catagory
    FROM MfrCatagory
    ORDER BY MfrCatagory.Catagory;

  10. #10
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    Maybe something like this in your current event will do the trick. Can't say I have ever tried doing something like this though.

    Code:
    Dim strSQL As String
    strSQL = "SELECT MfrCatagory.ManufacturerName, MfrCatagory.Catagory " & _
             "FROM MfrCatagory " & _
             "WHERE ManufacturerName = '" & Me![ManufacturerName] & "'" & _
             "ORDER BY MfrCatagory.Catagory;"
    If (SysCmd(acSysCmdGetObjectState, acForm, "FrmManufacturerAddlCatagoryEntry") And acObjStateOpen) = acObjStateOpen Then
        With Forms![FrmManufacturerAddlCatagoryEntry]
            .[lblManufacturerName].Caption = Me.ManufacturerName
            .RecordSource = strSQL
            .Requery
            .Repaint
        End With
    End If

  11. #11
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    513
    YAHOOOO !!!!

    big thanks (that did the trick!)

  12. #12
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    Good News!

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

Similar Threads

  1. Generate form based on combobox values
    By OatmealJones in forum Forms
    Replies: 3
    Last Post: 02-13-2013, 04:08 PM
  2. Updating Report based upon Updated Form
    By kelann in forum Forms
    Replies: 4
    Last Post: 11-02-2012, 07:42 AM
  3. Replies: 2
    Last Post: 10-10-2012, 07:01 AM
  4. Replies: 1
    Last Post: 03-27-2012, 05:25 PM
  5. updating a form with new values
    By markjkubicki in forum Programming
    Replies: 16
    Last Post: 08-27-2010, 10:08 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