I have a form with a combobox and a text box. I am running an insert query to add the data as a line. It adds the data alright the first time, but on any run after, it doesn't work. If I close and reopen the form, it will work once again. All code runs each time, but I don't get the insert
Private Sub btnAdd_Click()
'buffer values into variables to use exit function statements instead of end
Dim S As String
S = TheSystem
If S = "" Then Exit Sub
Dim N As String
N = TheNote
If N = "" Then Exit Sub
CurrentDb.Execute "insert into tblNotes values('" & S & "','" & Now() & "','" & N & "')"
Me.txtNote.Value = "Note added"
Me.Refresh
Dim WaitTill As Date
WaitTill = DateAdd("s", 1, Now())
Do Until Now() > WaitTill
DoEvents
Loop
Me.txtNote.Value = ""
End Sub
Private Function TheSystem() As String
If Nz(Me.cmbSystem, "") = "" Then
MsgBox ("Select a system")
TheSystem = ""
Exit Function
End If
TheSystem = Me.cmbSystem
End Function
Private Function TheNote() As String
If Trim(Nz(Me.txtNote, "")) = "" Then
MsgBox ("Enter note")
TheNote = ""
End If
If InStr(1, Me.txtNote, "'") Then
Dim YouSure As VbMsgBoxResult
YouSure = MsgBox("Having Apostrophes in notes will booger up the database. Replace all apostrophes' with accent marks`?", vbYesNo)
If YouSure <> vbYes Then End
Me.txtNote.Value = Replace(Me.txtNote.Value, "'", "`")
End If
TheNote = Me.txtNote
End Function