Want option of creating a new record without error messages.

B

Billy Smith

I'm using Access 2000 and VBA.

I have a simple bound form that displays a set of records. Sometimes,
when I am not interested in creating a new record, I scroll beyond
the last existing record, i.e. to the "new" record. When I immediately
try to scroll back to the previous record I get an error message
because it tries to save the "new" record it thinks I was trying
to create and of course some of the fields are null because I
didn't fill them in.

I want the option of creating a new record when I scroll to that
"new" record position (i.e. after the last existing record) but
I want to be able to just scroll back to the previous record without
error messages if I don't want to create a new record. How can I do this?

I'm thinking I should put up a yes/no msg box when I scroll to the
"new" record position. I've tried checking for current record in
the form's BeforeUpdate event routine, the Current event routine,
using the Undo method on the form and moving to the previous record
but still can't get it to do just what I want.

Any Ideas on how I can do this?

Thanks in advance.
 
B

Billy Smith

Just in case it helps someone else, here's a solution I came up with. This
combination of event procedures lets the user say whether he wants to create
a new record, do it if he wants, and scroll back to a previous record if he
does not.

Private bolCreatingNewRecord As Boolean

Private Sub Form­_Current
Dim intReturn As Integer
If Me.NewRecord Then
intReturn = MsgBox("Want to create new Task?", vbYesNo)
If intReturn = vbYes Then
bolCreatingNewRecord = True
Else
bolCreatingNewRecord = False
End If
End If
End Sub

Private Sub Form_BeforeUpdate
If Me.NewRecord Then
If Not bolCreatingNewRecord Then
Me.Undo
End If
End If
End Sub
 
J

Jason

Not sure what the problem is - I quite often scroll to the new record and
back. Without entering anything inthe new record you should just be able to
go back. However, if you have started entering in the record (you didn't
specify) then this error would occur if fields data is not valid for that
particular field.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top