Automatically save new record

CarlyS

Registered User.
Local time
Today, 08:24
Joined
Oct 9, 2004
Messages
115
I am wondering if anyone could tell me how to accomplish the following. It is a problem I have been wrestling with for days now.

I have a form with several subforms. Each subform has a different default value for time of day and then fields for data collected at that time, with default values of zero. The main form has data including the date and student name, which are linked to the subforms so they will fill in their data automatically.

When someone enters a day's data, some times of day will have data exactly like the default values (zero) and some times will have different numbers entered in. When people enter data, it saves without problem. However, when the data is the same as the default values, (and nothing gets typed in), it won't save the data. I understand that access doesn't recognize this as a new record because it hasn't been dirtied until someone types in it. I would like it to recogize a new record in the subform as soon as the date and student name fields are entered on the mainform (and the subform through the parent child links).

My attempt to get around this have not worked. Has anyone got an idea?

Thanks in advance,
Carly
 
The preferred method is to use left joins rather than inner joins in your queries. That way you won't have a problem with missing related records. The student will still be returned even if there is no data in the related table.

You are asking to create "empty" records. This is both inefficient and unnecessary. It is possible to do it but it requires some VBA. You'll need to create your own NewRecord flag and set it in the mainform's Current event. Define MyNewRecord as a global so it is available to all the procedures on the form.

Public MyNewRecord as boolean


Then in the main form's Current event:

Code:
If Me.NewRecord Then
    MyNewRecord = True
Else
    MyNewRecord = False
End If

Then in the main form's AfterUpdate event:

Code:
If MyNewRecord = True Then
    Me.Subform1.SomeField = something
    Me.Subform2.SomeField = something
    MyNewRecord = False
End If

change the field names as appropriate and use the default value as the "something" so as to avoid confusion.
 
Nothing happens

Hi Pat.
When I tried this code slightly altered to my forms, nothing happens at all. Any ideas why? Here is my code:

Private Sub Form_AfterUpdate()
If MyNewRecord = True Then
Me.FLASHDataEntrySubform1.Form!DataEntrySubform.Form!EntryDate = Now()
Me.FLASHDataEntrySubform2.Form!DataEntrySubform.Form!EntryDate = Now()
MyNewRecord = False
End If
End Sub
 
Is the variable properly defined?
Is there code to set the variable in the form's current event?

I see that your field names refer to a sub-sub form. You can't save a record in a sub-sub form until a record is saved in the sub form. You may have to nest this process. The main form would need to force a sub-form record to be saved and the sub-form would need to force the sub-sub-form record to be saved.
 
This is probably too good to be true...

Hi Pat,
Ok, this is what actually got it working, without the other steps. It is simply this code in the afterUpdate event. It is significantly simpler than what you had suggested, which worries me. I am hoping that I didn't properly explain myself in the first place and you will find that this does in fact serve as a suitable way to address the issue. What do you think:


Private Sub Form_AfterUpdate()

Me.FLASHDataEntrySubform1.Form!DataEntrySubform.Form!EntryDate = Date
Me.FLASHDataEntrySubform2.Form!DataEntrySubform.Form!EntryDate = Date


End Sub


The funny thing is that I think I had tried this before without success. :confused:

Thank you so much for your help!
 

Users who are viewing this thread

Back
Top Bottom