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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

add new record using button on continuous form

Status
Not open for further replies.

tania20

Programmer
Oct 30, 2006
148
AU
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
 
Use DAO

Yoy will of corse have to add a referance to the DAO in yor referances
Hope this helps

Jimmy

Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String
Set db = CurrentDb
Set rs = db.OpenRecordset("YourTable", dbOpenDynaset)
rs.AddNew
rs!t_date = Date
rs!t_time = Time

rs.Update

Me.Requery

 
thanks for the advice...got this code to work, which was close to what i had:

Private Sub AddRecordButton_Click()
Me.AllowAdditions = True
DoCmd.GoToRecord , , acNewRec
End Sub

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


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top