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