add new record on cts form with button

tanzania

Registered User.
Local time
Yesterday, 19:26
Joined
Oct 20, 2006
Messages
91
Hi, I have a continuous form. Im wandering if there is some way of not showing the last record whilst still allowing additions? ie I am wanting to have an 'Add' button that will insert a new record and automatically populate the date and time fields with the current values. The following code works fine on allowing additions, but once the fields have been populated it no longer even shows a new record, and subsequent presses of the button adds a new records but its all warped and does not show in the normal continuous way.

DoCmd.GoToRecord , , acNewRec

If IsNull(t_date) Then

t_date = Date
t_time = Time

End If
Me.ctlt_Type.SetFocus
 
In Design View for the form goto Properties - Data and set AllowAdditions to No
Code:
Private Sub AddRecordButton_Click()
  Me.AllowAdditions = True
  DoCmd.GoToRecord , , acNewRec
End Sub

Code:
Private Sub Form_Current()
  If Not Me.NewRecord Then 
    Me.AllowAdditions = False
  Else 
    Me.t_date = Date
    Me.t_time = Time
    Me.ctlt_Type.SetFocus
  End If
End Sub

I can't check this right now, but I believe it'll do the job for you.

Linq
 
that works beautfully!...thanks heaps for getting me in the rigth direction!
 

Users who are viewing this thread

Back
Top Bottom