Add a new record

  • Thread starter Thread starter KR
  • Start date Start date
K

KR

Hi,

Here is the problem:

The form on activation is set to add a new record using this command

DoCmd.GoToRecord acDataForm, "frmFormName", acNewRec

However it is not actually adding that record in the table until the
user completes data entry and navigates away from it. Is there a way
to save the record as the user completes the entry on the form.

Thanks
KR
 
Don't know why you'd want to do it that way, but in the AfterUpdate event of
any control which requires input from user, you can use:

If Me.Dirty then
Me.Dirty = False
End if

Brian
 
Well, it is something I just inherited, and I am new to Access -

I realized that I did not explain the whole process -

When this forms opens, it opens to a new record, but still does not
have the PrimaryID key field is not yet populated (This is set to
Autonumber). The user does all the entry and there is a button to
preview this form in report format - which is actually a report. The
button event goes like this -

stDocName = "rptReportName"
stLinkCriteria = "[ID] =" & Me![ID]
DoCmd.OpenReport stDocName, acPreview, , stLinkCriteria

Since the ID key has not been populated the preview does not work until
the user navigates away from the new record and then comes back to it.

Thanks
KR
 
The default action of an autonumber is such that when you first start typing
into a new record (dirty the record), the autonumber is assigned. However,
if you try to run a report with the newly created autonumber, you must first
save the record, hence the If Me.Dirty ... to write the record to the table.
But if, as you say, the autonumber is not populating, then this leads me to
believe that you are using an unbound form for data entry. Is this so?

Brian
 
I don't believe it is an unbound form for data entry.

Anyway, I was in a hurry to get this done, so I just added a save
button to the form as a workaround. However, I will use the IF
Me.Dirty to test it out.

Thanks much

KR
 
Back
Top