Results 1 to 7 of 7
  1. #1
    floyd is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2013
    Posts
    66

    Save button SAVING... and RESETTING FORM... but giving ERROR.


    I have a coded "save button" cmdSave so my fields aren't being updated as people click through my form. (I was getting 10+ blank form inputs per day that I had to clear out).

    Here is the problem.
    When you input something in the form and hit "Save"... it works GREAT!
    When you try to leave the form though... it thinks there is info and asks if you want to save.

    I know this is simple... but I can't figure out how to get it to let you go.

    Code:
    Option Compare Database
    Option Explicit
    Private blnGood As Boolean
     
    --------------------------
    ' This finds a file and links it to the DB
    
    Private Sub FindFileInput_Click()
    
        Dim f As Object
        Dim strSelectedpath As String
        Dim strSelectedFile As String
        Dim varItem As Variant
    
        Set f = Application.FileDialog(3)
        f.AllowMultiSelect = False
        
        If f.Show = -1 Then
            For Each varItem In f.SelectedItems
                 strSelectedpath = varItem & "#" & varItem
                 strSelectedFile = Split(strSelectedpath, "\")(UBound(Split(strSelectedpath, "\")))
                 Next varItem
                 Me![txtSelectedFile] = strSelectedpath
                 Me![txtFileName] = strSelectedFile
                 
    Dim Msg, Style, Title, Help, Ctxt, Response, MyString
    
    Msg = "File association successful"
    Style = vbOKOnly + vbInformation + vbDefaultButton1
    Title = "Association"
    Help = "DEMO.HLP"
    Ctxt = 1000
    
    Response = MsgBox(Msg, Style, Title, Help, Ctxt)
    
    If Response = vbYes Then    ' User chose Yes.
        MyString = "Done"    ' Perform some action.
    End If
                 
        End If
        Set f = Nothing
    
    End Sub
    ----------------
    'find who input the file
    
    Private Sub Form_Current()
        If Me.NewRecord Then
            CreateBy = Environ("username")
        End If
    End Sub
    
    ---------------------------
    'Security on form
    Private Sub Form_Open(Cancel As Integer)
    If User.AccessID = 3 Then
        MsgBox "You are not authorized to open this form!", vbOKOnly + vbExclamation
        Cancel = True
    End If
    
    End Sub
    
    -------------------------
    'Save Button
    
    Private Sub cmdSaveResource_Click()
        blnGood = True
        Call DoCmd.RunCommand(acCmdSaveRecord)
        DoCmd.GoToRecord , , acNewRec
        blnGood = False
    End Sub
     
    Private Sub Form_BeforeUpdate(Cancel As Integer)
        Dim strMsg As String
     
        If Not blnGood Then
            Cancel = True
            strMsg = "Please use the Save button to save your changes," & _
                     vbNewLine & "or Escape to reset them."
            Call MsgBox(Prompt:=strMsg, Title:="Before Update")
        End If
    End Sub
    
    

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Try step debugging. Follow the code as it executes, one line at a time.

    I think you will find that the code in the If clause of the BeforeUpdate always runs.

    The default value of a Boolean variable is False. So between that and your code and using the Not operator, the condition always returns True. Try:

    If blnGood = True Then

    I really don't see how blnGood can ever be anything but False with this structure.

    Why must users use Save button? Record is committed to table when move to another record, close form, or run code.
    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
    Quote Originally Posted by June7 View Post

    ...Why must users use Save button? Record is committed to table when move to another record, close form, or run code...
    And 'clicking through a Form' doesn't create blank Records!
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  4. #4
    floyd is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2013
    Posts
    66
    I guess they are placing their cursor on one of the input fields and then moving to another form.
    I keep getting blank file inputs.

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Just clicking in a control won't automatically create a record either. Something else is happening. If something is entered then removed from the field (like with backspace or ESC) and then leave the record, it will be committed.
    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.

  6. #6
    NTC is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2009
    Posts
    2,392
    there is really a disconnect between the topic of having empty records generated vs code for relinking.....kind of like using a jack hammer to tap in a thumb tack.....

    my humble advice; leave your linking linked. Instead relook at your form and the human experience..... your table/form should have or probably has an autonumber - - if not add that and make it temporarily visible because it is a useful aid..... when in the form and at a record that auto number value is "(new)" or possibly it has a value.......a new record is made when the auto number field increments....and so you should figure out what is triggering that and deal with it in an alternative way.......

  7. #7
    floyd is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2013
    Posts
    66
    NTC... that is really an interesting idea!!!
    Let me see what is going on and I will report back.

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

Similar Threads

  1. form - save entered data only with save button
    By cbrxxrider in forum Forms
    Replies: 3
    Last Post: 10-20-2013, 12:39 PM
  2. Replies: 11
    Last Post: 09-21-2013, 04:53 AM
  3. Replies: 3
    Last Post: 10-08-2012, 08:40 AM
  4. Access Form- Save/Close Button error
    By Ashe in forum Forms
    Replies: 3
    Last Post: 02-10-2011, 01:01 PM
  5. VB coding for saving when click on save button in form
    By cwwaicw311 in forum Programming
    Replies: 1
    Last Post: 02-04-2010, 11: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