populate date in subform

  • Thread starter Thread starter redrover
  • Start date Start date
R

redrover

I'm using a subform that includes a date field. The user enters the date and
at least 1 other value for each record in the subform. I'd like to
automatically update any subform records that contain blank date fields with
the first date that the user enters. I'm sure I need to use VB coding to
perform this but I'm having difficulty getting started. Can anyone suggest a
method to get this done?
 
I'm using a subform that includes a date field.  The user enters the date and
at least 1 other value for each record in the subform.  I'd like to
automatically update any subform records that contain blank date fields with
the first date that the user enters.  I'm sure I need to use VB coding to
perform this but I'm having difficulty getting started.  Can anyone suggest a
method to get this done?

you could have some VBA that loops through pertinent records and adds
the date if neccesary.

Dim rs as DAO.Recordset
Dim db as DAO.Database
set db = CurrentDb
set rs = db.Open("SELECT [the date field you want to update].[your
table/query name] WHERE [the primary key of that table].[your table/
query name] = " & me.[name of field that contains the child field])
rs.MoveFirst
Do while Not rs.EOF
if IsNull (rs![the date field you want to update]) Then
With rs
.Edit
rs!![the date field you want to update] = me.[name of date field the
user just updated]
.Update
End with
End If
rs.MoveNext
Loop
 
I'm using a subform that includes a date field.  The user enters the date and
at least 1 other value for each record in the subform.  I'd like to
automatically update any subform records that contain blank date fields with
the first date that the user enters.  I'm sure I need to use VB codingto
perform this but I'm having difficulty getting started.  Can anyone suggest a
method to get this done?

you could have some VBA that loops through pertinent records and adds
the date if neccesary.

Dim rs as DAO.Recordset
Dim db as DAO.Database
set db = CurrentDb
set rs = db.Open("SELECT [the date field you want to update].[your
table/query name] WHERE [the primary key of that table].[your table/
query name] = " & me.[name of field that contains the child field])
rs.MoveFirst
Do while Not rs.EOF
if IsNull (rs![the date field you want to update]) Then
With rs
.Edit
rs!![the date field you want to update] = me.[name of date field the
user just updated]
.Update
End with
End If
rs.MoveNext
Loop

You could add this code to the form after update event


Private Sub Form_AfterUpdate()
Dim rs as DAO.Recordset
Dim db as DAO.Database
set db = CurrentDb
set rs = db.Open("SELECT [the date field you want to update].[your
table/query name] WHERE [the primary key of that table].[your table/
query name] = " & me.[name of field that contains the child field])
rs.MoveFirst
Do while Not rs.EOF
if IsNull (rs![the date field you want to update]) Then
With rs
.Edit
rs!![the date field you want to update] = me.[name of date field the
user just updated]
.Update
End with
End If
rs.MoveNext
Loop
End Sub
 
I forgot the FROM statement in my SQL

set rs = db.Open("SELECT [the date field you want to update].[your
table/query name] FROM [your table/query name]
WHERE [the primary key of that table].[your table/
query name] = " & me.[name of field that contains the child field])
 
I'll give this a try -- will there be a problem updating the recordsource
since I already have it open in the subform?
 

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

Back
Top