The Allen Browne article JBB pointed you to gives you a couple of methods to do this, but FYI, Access also provides a fairly easy way. When in the next Record'sControl for the Field in question, simply use the keyboard shortcut
<Ctrl> + <'>
This is a good way to do it if you sometimes but not always want to do this.
John Big Booty's solution is working, but when i go to the next record it does not work. When i close the form and open it again it works. It gets the last record form the table.
In your form, you can use the AfterUpdate event of the control holding your data to set the DefaultValue for the Field. From that time forward, until you either manually change the data or close your form, the data will be entered automatically in each new record.
Code:
Private Sub YourControlName_AfterUpdate()
Me.YourControlName.DefaultValue = """" & Me.YourControlName.Value & """"
End Sub
In your form, you can use the AfterUpdate event of the control holding your data to set the DefaultValue for the Field. From that time forward, until you either manually change the data or close your form, the data will be entered automatically in each new record.
Code:
Private Sub YourControlName_AfterUpdate()
Me.YourControlName.DefaultValue = """" & Me.YourControlName.Value & """"
End Sub
Just re-checked and it works fine for me with Text, Integer and Date Fields! I seem to remember, from the dark recesses of my mind, someone reporting that they had to enter the code and save the Form before running it, in order for it to work.
But you can try a Date/Time Field specific syntax and see if it works for you
Code:
Private Sub YourDateFieldlName_AfterUpdate()
YourDateFieldlName.DefaultValue = "#" & Me.YourDateFieldlName.Value & "#"
End Sub
Not working ... maybe b/c i made a button for today's date...
Code:
Private Sub DanasnjiDatum_Click()
On Error GoTo Err_DanasnjiDatum_Click
Me.DATUM_IZVESTAJA = Date
DoCmd.RunCommand acCmdApplyFilterSort
Exit_DanasnjiDatum_Click:
Exit Sub
Err_DanasnjiDatum_Click:
MsgBox Err.Description
Resume Exit_DanasnjiDatum_Click
End Sub
And this is the code for afterupdate
Code:
Private Sub DATUM_IZVESTAJA_AfterUpdate()
Me.DATUM_IZVESTAJA.DefaultValue = """" & Me.DATUM_IZVESTAJA.Value & """"
End Sub
That's because most events associated with a Control, including the AfterUpdate event, only fire if the value is physically entered/selected! To use the AfterUpdate when entering the Control's Value via code, you'd have to explicitly Call it. So, instead of
Code:
Me.DATUM_IZVESTAJA = Date
use
Code:
Me.DATUM_IZVESTAJA = Date
Call DATUM_IZVESTAJA_AfterUpdate
That's because most events associated with a Control, including the AfterUpdate event, only fire if the value is physically entered/selected! To use the AfterUpdate when entering the Control's Value via code, you'd have to explicitly Call it. So, instead of
Code:
Me.DATUM_IZVESTAJA = Date
use
Code:
Me.DATUM_IZVESTAJA = Date
Call DATUM_IZVESTAJA_AfterUpdate