Results 1 to 10 of 10
  1. #1
    whisp0214 is offline Advanced Beginner
    Windows XP Access 2016
    Join Date
    May 2017
    Posts
    30

    Save some text fields and clear others

    I have a data entry form with 7 combo boxes and text fields. Once the data is all entered they hit a button(save & new) and the form clears so they can make another entry. What I would like to do is have only 3 text boxes clear and the other 4 remain filled in when the save button is clicked. I have tried using requery and null on only the desired boxes to no avail. Does anyone have a suggestion that can point me in the right direction?

    Thanks in advance.

    Garret

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    This is a BOUND form and you are simply moving to a new record row? What value do you want in the 4 textboxes - the last values entered by users? Use code in each control AfterUpdate event to set its DefaultValue property.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    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 could do it in the Control's AfterUpdate event, as June7 suggested (and this is where most developers do this) but I see no reason why it wouldn't work if you put it at the beginning of your 'save & new' button's OnClick code:

    Code:
    Me.ControlToSave1.DefaultValue = """" & Me.ControlToSave1.Value & """"  
    Me.ControlToSave2.DefaultValue = """" & Me.ControlToSave2.Value & """"  
    Me.ControlToSave3.DefaultValue = """" & Me.ControlToSave3.Value & """"

    The nice thing about this code is that it is valid for Text, Number, Date and Yes/No Field Datatypes!

    Linq ;0)>

  4. #4
    whisp0214 is offline Advanced Beginner
    Windows XP Access 2016
    Join Date
    May 2017
    Posts
    30
    Thanks Missinglinq and June 7. That code accomplished what I wanted, but now I ran into another stumbling block. My reset button no longer resets the controls that I changed the Default Value to. I have tried setting each field to Null and used the me.controlname = "" to no avail. Any suggestions?

  5. #5
    whisp0214 is offline Advanced Beginner
    Windows XP Access 2016
    Join Date
    May 2017
    Posts
    30
    Nevermind. I just had to reorder the code on my reset button and reset the default value to null. Thanks again!

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    Why would you even set BOUND data controls to null or empty string? If you move to new record row they should be empty.

    Exactly what is the design and code for this form? Is it a BOUND form with BOUND controls?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    whisp0214 is offline Advanced Beginner
    Windows XP Access 2016
    Join Date
    May 2017
    Posts
    30
    It is a data entry form with 7 controls, and it is BOUND with BOUND controls. When a person is entering multiple items, which happens frequently, I wanted 4 of the controls to remain after they save the entry. Basically those 4 items change infrequently and the other 3 change every time. That way the user only has to enter 3 things instead of 7 for every new entry. When they need to change all 7, they can then hit the reset button and start from scratch.

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    Don't understand the issue. If user does not want those values then they can change them which will also trigger setting the DefaultValue property to those new inputs.
    Last edited by June7; 10-26-2017 at 01:20 AM.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    whisp0214 is offline Advanced Beginner
    Windows XP Access 2016
    Join Date
    May 2017
    Posts
    30
    The 7 controls are empty to start, then the user fills in all 7(nothing Auto Populates). They click a button called Save & New(this is where I put the code like Missinglinq mentioned). After the on click event, 4 controls stay as they were entered and 3 reset to blank. Now the user can just enter information in those 3 controls for their next entry. They can keep repeating this process until they need to change all 7. Then they click the reset button(where i put the code from Missinglinq with modifications) which resets the 4 controls default value to nothing. My code is below if that helps.

    [Private Sub cmdClear_Click() On Error GoTo cmdclear_click_err

    Me.cboSalesID.DefaultValue = Null & Me.cboSalesID.Value & """"
    Me.cboAssistantID.DefaultValue = Null & Me.cboAssistantID.Value & """"
    Me.cboVendorID.DefaultValue = Null & Me.cboVendorID.Value & """"
    Me.cboRetailerID.DefaultValue = Null & Me.cboRetailerID.Value & """"

    If Me.Dirty = True Then
    DoCmd.RunCommand acCmdUndo


    Exit Sub
    End If


    cmdclear_click_exit:
    Exit Sub

    cmdclear_click_err:
    MsgBox Error$
    Resume cmdclear_click_exit

    End Sub



    Private Sub cmdsave__new_Click()
    On Error GoTo cmdsave_new_click_err

    DoCmd.Save

    Me.cboSalesID.DefaultValue = """" & Me.cboSalesID.Value & """"
    Me.cboAssistantID.DefaultValue = """" & Me.cboAssistantID.Value & """"
    Me.cboVendorID.DefaultValue = """" & Me.cboVendorID.Value & """"
    Me.cboRetailerID.DefaultValue = """" & Me.cboRetailerID.Value & """"

    DoCmd.Requery

    cmdsave_new_click_exit:
    Exit Sub

    cmdsave_new_click_err:
    MsgBox Error$
    Resume cmdsave_new_click_exit

    End Sub]

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    If you want to clear the DefaultValue property then don't reference the controls.

    Me.cboRetailerID.DefaultValue = ""
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 2
    Last Post: 10-03-2012, 02:58 AM
  2. Replies: 8
    Last Post: 09-27-2012, 11:12 AM
  3. Macro to add and clear fields
    By Skroof in forum Access
    Replies: 1
    Last Post: 05-14-2012, 01:13 PM
  4. Clear some fields and not others
    By funkygoorilla in forum Access
    Replies: 12
    Last Post: 08-23-2011, 07:38 AM
  5. Clear fields in a record
    By stryder09 in forum Access
    Replies: 9
    Last Post: 05-12-2011, 01:34 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