Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Commit Action During Record Navigation

Status
Not open for further replies.

bvbowes

Programmer
Oct 12, 2006
21
US
I want to be able to add some code that gets run every time someone uses the embedded "go to next record" navigation arrow at the bottom of the form, is that possible?

When users add some notes to an unbounded text box on the form the text will stay in each record they navigate to until the user hits an "Add Note" button that I created.
 
The Current event procedure is fired each time the user navigates to another record.
BTW, why mixing bound and unbound (but updatable) controls ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Nice, thanks, I didn't know about the "On Current" event

I've added some code to just pop up a reminder to add the text (via a cmd button that already exists) but the form goes to the next record any way. Any way to stop it?

Here is what I've built so far.

Private Sub Form_Current()
If Not IsNull(Me!Notes12) Then 'stop navigation forward and then...
MsgBox "Please add your note before moving forward!", vbOKOnly, "Oops..."
Else ' or something needs to be here to stop the navigation to the next record
End If
End Sub
 
Just a though.
In the AfterUpdate event procedure of Notes12:
Me.Dirty = True ' the Form_BeforeUpdate will fire

In the BeforUpdate event procedure of the Form:
If Trim(Me!Notes12 & "") <> "" Then
MsgBox "Please add your note before moving forward!", vbOKOnly, "Oops..."
Cancel = True
Exit Sub
End If

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Yeah I tried that already, only bound fields can be modified with BeforeUpdate.
 
Are you saying that the AfterUpdate event procedure of Notes12 never fires ?
 
It fires great...I get this error message though in the after_update:

Run-time error '7768':

In order to change data through this form, the focus must be in a bound field tha can be modified.
 
What I meant to say is that dirty only works with bounded items....
 
Me![some bound control].SetFocus
Me.Dirty = True

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
What is the value of the AllowEdits property of the form ?
Is the underlaying query updatable ?
You still didn't reply my question:
why mixing bound and unbound (but updatable) controls ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Allow Edits = Yes

Yes it is updatable

I have it unbound so that I can pass the notes to a tbl that houses only the notesid, notes, windows user name, and timestamp where any form can pull the notes data into itself.
 
And how are the notes related (linked, joined) to the current record ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I have a note table that is linked to the main form where the case number is via case number. But in order to have a one to many I just insert the max note id + 1 and insert the current case number at the same time.

Here is the code.

Function AddNotes()
Dim SqlAddNote As Variant
Dim db As Database
Set db = CurrentDb
Dim con As New ADODB.Connection
Set con = CurrentProject.Connection
Dim rst As New ADODB.Recordset

autoplus1 = "SELECT Max([tblNotes.NotesID]) AS MaxOfNotesID FROM tblNotes"
rst.Open autoplus1, con, adOpenDynamic, adLockOptimistic

AutoID_Count = rst!MaxOfNotesID
Autonumber = AutoID_Count + 1

CaseNumber = Forms!frmMainEntry.ControlName.CaseNumber1
Note1 = Forms!frmMainEntry.Notes12
SqlAddNote = "INSERT INTO [tblNotes] values ('" & Autonumber & "','" & Note1 & "','" & Now() & "','" & CaseNumber & "','" & WinUserName() & "')"
CurrentDb.Execute SqlAddNote, dbFailOnError
Notes = ""

con.Close
Set con = Nothing
rst.Close
Set rst = Nothing
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top