Results 1 to 6 of 6
  1. #1
    markjkubicki's Avatar
    markjkubicki is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    496

    execute code on subform without adding a record

    I have a subform with a couple command buttons in the form footer. One of the controls is a toggle button that simply changes the backcolor of the form's detail section (as way for the user to remind themselves that the information in the detail entries may need some addtional work / editing / entries / etc.)
    The problem is that when there are no entries in the detail section, clicking the contol, adds an entry. Although the entry is blank, it is unnecessary, and causes problems later on.
    Is there a line of code that I can add to allow the procedure to execute without adding the blank entry to the subform's data source?

    Const NormalColor As Long = -2147483643
    Const FlagColor As Long = 9434879

    Private Sub tglInstallationNoteFlag_Click()
    If Me.tglInstallationNoteFlag = False Then
    Me.Detail.BackColor = NormalColor
    Else
    Me.Detail.BackColor = FlagColor
    End If
    End Sub

    thanks in advance,


    mark

  2. #2
    Toyman is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Posts
    233
    Quote Originally Posted by markjkubicki View Post
    I have a subform with a couple command buttons in the form footer. One of the controls is a toggle button that simply changes the backcolor of the form's detail section (as way for the user to remind themselves that the information in the detail entries may need some addtional work / editing / entries / etc.)
    The problem is that when there are no entries in the detail section, clicking the contol, adds an entry. Although the entry is blank, it is unnecessary, and causes problems later on.
    Is there a line of code that I can add to allow the procedure to execute without adding the blank entry to the subform's data source?

    Const NormalColor As Long = -2147483643
    Const FlagColor As Long = 9434879

    Private Sub tglInstallationNoteFlag_Click()
    If Me.tglInstallationNoteFlag = False Then
    Me.Detail.BackColor = NormalColor
    Else
    Me.Detail.BackColor = FlagColor
    End If
    End Sub

    thanks in advance,
    mark
    You can disable the toggle button when there is no record. Try this by putting the code in the "on current" event of your form.

    Dim sKey As Integer
    sKey = Nz(Me.YourPrimaryKeyField, 0) 'assuming it is a number field. If it is text, change the declearation for sKey to "string"
    If sKey <> 0 Then
    Me.tglInstallationNoteFlag.Enabled = True
    Else
    Me.tglInstallationNoteFlag.Enabled = False
    End If

  3. #3
    markjkubicki's Avatar
    markjkubicki is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    496
    Let's assume that the main record is for a widget as part of a larger order that is being put together, the subform would then contain, if necessary, a list of accesories for that widget... The the sales person may want to flag to himself (by clicking this toggle control and changing the subforms detail back color) that thef have not yet entered the accessories...

    In this case, I would want the control to be active although there are currently no records

    (...hope thi help clarifios where I am going?)

  4. #4
    hertfordkc is offline 18 year novice
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    481

    Not sure about your criteria for saving a record, but

    in Form_BeforeUpdate, you could DoCmd.CancelEvent if you want to check the form entries there. Or use me.Undo. You need to look at the event sequence to see where your error checking and intervention is needed.

  5. #5
    Toyman is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Posts
    233
    Quote Originally Posted by markjkubicki View Post
    Let's assume that the main record is for a widget as part of a larger order that is being put together, the subform would then contain, if necessary, a list of accesories for that widget... The the sales person may want to flag to himself (by clicking this toggle control and changing the subforms detail back color) that thef have not yet entered the accessories...

    In this case, I would want the control to be active although there are currently no records

    (...hope thi help clarifios where I am going?)
    In your case, the reason the radio control creates a new record is because your control is bound to the table containing the sales items. Even though there is no record when you go to the sales items' sub form, when you click to enable the radio control button, you actually create a new sales item record. To get around that, you can put the check control field in the main record (sales) and have the radio control field in the main form. Code it so that if it is checked, the color changes in your sub form

  6. #6
    markjkubicki's Avatar
    markjkubicki is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    496
    adding me.undo in front of my code (at the control's click event) worked perfectly...
    thanks

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

Similar Threads

  1. How to execute Line of Code
    By jo15765 in forum Programming
    Replies: 4
    Last Post: 06-22-2011, 05:37 PM
  2. Write Code to Navigate from Subform to Subform
    By Swilliams987 in forum Programming
    Replies: 22
    Last Post: 02-04-2011, 11:30 AM
  3. After adding data on subform
    By Nancy in forum Forms
    Replies: 9
    Last Post: 12-22-2010, 06:19 PM
  4. Can't get any of my code to execute!
    By blacksaibot in forum Programming
    Replies: 4
    Last Post: 03-16-2010, 08:08 AM
  5. Adding VB code on a embedded coding for a button
    By cwwaicw311 in forum Programming
    Replies: 1
    Last Post: 02-20-2010, 12:25 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