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

Populate remaining fields in column 2

Status
Not open for further replies.

infact

Technical User
Jan 9, 2006
27
US
On a form (tabular) that will list 30 records I have a date field with a drop down list to select a date to populate the field. The date will be the same for all 30 records, so is there a way to autofill or populate the rest of the fields with the selected date instead of having to do this 30 separate times ?
Thanks.
 
You can try like this...

Code:
Private Sub DateField_AfterUpdate()
Dim rs As DAO.Recordset
Set rs = Me.RecordsetClone
rs.MoveLast
rs.MoveFirst
While rs.EOF = False
    rs.Edit
    rs.datefield = Me.datefield
    rs.Update
    rs.MoveNext
Wend
Close rs

However for this code to work you have to add reference to
"Microsoft DAO 3.5 Object Library"
OR
"Microsoft DAO 3.6 Object Library"
OR
Any "Microsoft DAO Object Library"

If the form does not show all 30 dates
Just issue "Requery" command

Hope this helps...
Regards
 
Assuming there is some criteria that limits the records in the subform, you should be able to create and run an update query.

Another option is to use DAO code like the following:
Code:
Private Sub cmdUpdates_Click()
    Dim rs As DAO.Recordset
    Set rs = Me.sfrmOrderDetailsDS.Form.RecordsetClone
    With rs
        .MoveFirst
        Do Until .EOF
            .Edit
            .Fields("DateField") = Me.OrderDate
            .Update
            .MoveNext
        Loop
        .Close
    End With
    Set rs = Nothing
End Sub

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Before adding the code to populate all the date fields, I realized that I forgot to add one more field for inputting a number. I created a texbox for this, tested it by entering a value, hit enter, and all 30 fields down the column became populated with the first entry value. The value in this field for each of the 30 records is different. This is what I want to happen to the date field, not this one. Is there a switch to set in properties for this field to prevent the autopopulating of this entire column ?
Thanks, again.
 
The value of the textbox is showing same value for all 30 records because it is a unbound control. Even though it shows the way you want, you cannot save its value directly to the underlaying table. It is necessary to use the RecordSetClone code as provided in previous post to assign same date values for all the 30 records. You cannot use your textbox method to assing same date value to each of your 30 records.

In case you wish to store different values in the textbox you will have to bound it to some field. Unless the textbox is bound to a field, you will not be able to enter different values for each of 30 records. As long as the textbox remains unbound, it will show the same values for all the 30 records.

This is the way bound and unbound fields work.

Regards,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top