Results 1 to 14 of 14
  1. #1
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904

    Tricky Dynamic Form for Updating Existing Data

    I have a query that returns data in a layout similar to what is shown below.


    Company Form Name Receives Form? Date Form Complete Notes Autonum
    ABC Co. Form 123 Yes 8/16/2012 Faxed copy to client 1
    ABC Co. Form 456 No 2
    ABC Co. Form 789 No 3
    XYZ Inc. Form 123 No 4
    XYZ Inc. Form 456 No 5
    XYZ Inc. Form 789 Yes 7/17/2012 6

    I am trying to create a dynamic form where users can only update existing records. Essentially, there is a record selection form, where the user will select which client they wish to update (i.e. ABC Co.). I then have VBA code to build the SQL code to select just that client's record from the above query (and that is used as the Control Source of my Form).

    So, in the Form Header section of the Form, I just show the Company Name. The other four fields are placed in the Details section (not displaying the Autonum field). Since ABC Co. has three records, there are three records returned in the Detail section.

    Now, here comes the tricky part. The "Receives Form?" field is a check box that they can toggle on/off. When it is toggled on, I want it to enable the "Date Form Complete" and "Notes" fields for updating. However, when it is toggled off, I want these two fields to be disabled. And of course, I only want the toggling on/off to affect that particular record. The issue that I am having is that my toggling seems to affect all three records on the Form.

    Here is what my VBA code looks like:
    Code:
    Private Sub Form_Load()
    '   Run check box defaults
        Call Detail_Defaults
    End Sub
    
    Private Sub chkReceivesForm_Click()
        Call Detail_Defaults
    End Sub
    
    Sub Detail_Defaults()
        If Me.chkReceivesForm = 0 Then
            Me.dteCompletionDate.Enabled = False
            Me.strNotes.Enabled = False
        Else
            Me.dteCompletionDate.Enabled = True
            Me.strNotes.Enabled = True
        End If
    End Sub
    Does anyone have any idea how I can modify this so selecting a check box only enables/disables the fields associated with that single record, and doesn't affect the other ones?

    Thanks

  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
    This type of code doesn't work well in forms, as you've found. You could add it to the current event, so it would be correct record by record. Have you looked at Conditional Formatting? That would get the overall look correct (some records enabled, some not).
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    You could add it to the current event, so it would be correct record by record.
    Thanks. I'll have to play around with that.
    Have you looked at Conditional Formatting? That would get the overall look correct (some records enabled, some not).
    I know I can change the appearance of it using Conditional Formatting, but its not possible to actually enable/disable fields using Conditional Formatting, is it?

  4. #4
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    I just tried putting my code in the Current Event, and it exhibited the same type of behavior.
    Do I need to incorporate some sort of loop so that it goes through each record to handle them individually?
    If so, any idea on how might do that?

    Or can I re-structure my form in such a way to accomplish what I want?

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Yes, disabling is an option with Conditional Formatting. On my PC it's the option to the far right. The current event should work, but the formatting would be relative to the selected record, which is why I think CF is the better option.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    CF is really the only option, in a Continuous or Datasheet View Form, if you want the individual Record's appearance to reflect its Enabled/Disabled status.

    If you didn't care about the appearance, you could use the Lock Property in the Form_Current event, and the Records would be appropriately editable/non-editable, according to the Checkbox status on the Record you are currently on, but the Controls on all Records would look the same.

    The reason for this behavior is that there is only one [B]dteCompletionDate Control and only one strNotes Control! What you are seeing on multiple Records are multiple instances of each Control, but there is only one Control of each name, and the way it is Formatted, on the Current Record, is the way all instances will be Formatted.

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  7. #7
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Thanks guys. I will use these tips and play around with it a bit more when I am back in the office on Monday, and let you know how it all works out.

  8. #8
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Yes, disabling is an option with Conditional Formatting. On my PC it's the option to the far right. The current event should work, but the formatting would be relative to the selected record, which is why I think CF is the better option.
    Paul,

    That is a cool feature, I never knew Conditional Formatting had an Enable/Disable option.
    It works exactly like I want it to, and is a whole heck of a lot easier than trying to control it using Events.

    Thanks a million!

    linq,

    Thanks for your insights too!

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #10
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    A quick follow-up (and I am afraid I can already guess the answer...).

    Using Conditional Formatting to disable worked great on my Text Boxes.
    I was also hoping to use Conditional Formatting to disable a single Check Box.
    It appears that one cannot apply Conditional Formatting to Check Boxes on a Form.
    Is that, indeed, the case?

    Thanks

  11. #11
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    In the immortal words of Ed McMahon, "you are correct sir".
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  12. #12
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    "Hi-oh!"

    Not a big deal. They can click away all they want at that one, it just won't do anything.

  13. #13
    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 think we both just dated ourselves.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  14. #14
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    You're only old if you remember when the show was in B&W and was on the air for 90 minutes!
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

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

Similar Threads

  1. Replies: 3
    Last Post: 08-28-2012, 02:27 PM
  2. Replies: 4
    Last Post: 02-07-2012, 12:16 PM
  3. updating existing report with new data in table
    By newtoaccess123 in forum Reports
    Replies: 2
    Last Post: 10-18-2011, 09:50 AM
  4. Replies: 4
    Last Post: 05-30-2011, 08:20 PM
  5. Updating an Existing Table
    By jo15765 in forum Access
    Replies: 2
    Last Post: 11-21-2010, 09:11 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