G
Guest
I am trying to automate producing a set of records in a schedule. I have a
table called "HouseSchedule" with multiple task records in it. Each house
has a set of records in this table and there is a "Master" set of records. I
am using a form with a couple of drop down buttons so that a user can select
a "Master" set of records from the table, copy those records, place them back
in the table and change the HouseID field from "Master" to "HouseNumberX".
I have thought of a number of ways to do this including Append Query or VBA
code, however I have had very little success. I can create a query and/or a
form that selects the "Master" set of records; however, I have not yet been
able to overwrite the HouseID field to the new house's "HouseNumber".
1. What is the best approach? Append Query or Code?
2. The code I came up with is below, but I constantly get stuck at the Do
Loop and inside when trying to set the field value to "New Address".
Private Sub CopyScheduleButton_Click()
'This procedure will copy a set of schedule records (typically a master)
'Add them to the schedule and change the address of each record to that
'of the one on the Schedule Form "Select Address" drop down
Dim NewAddress As String
NewAddress = Forms!Schedule!ComboAddressSelect.Value
DoCmd.OpenForm "CopyScheduleQuery", acFormDS ' use a query or a form based
on a query?
Recordset.MoveFirst
Do While Recordset.EOF = False 'Program Crashes here
Recordset.Address.Value = NewAddress 'Program also crashes here when
removed from loop
Recordset.MoveNext
Loop
'Copy records to Schedule Table
'?Unsure how to move these into Schedule table
'Requery Schedule
DoCmd.RunMacro ("RequerySchedule")
End Sub
table called "HouseSchedule" with multiple task records in it. Each house
has a set of records in this table and there is a "Master" set of records. I
am using a form with a couple of drop down buttons so that a user can select
a "Master" set of records from the table, copy those records, place them back
in the table and change the HouseID field from "Master" to "HouseNumberX".
I have thought of a number of ways to do this including Append Query or VBA
code, however I have had very little success. I can create a query and/or a
form that selects the "Master" set of records; however, I have not yet been
able to overwrite the HouseID field to the new house's "HouseNumber".
1. What is the best approach? Append Query or Code?
2. The code I came up with is below, but I constantly get stuck at the Do
Loop and inside when trying to set the field value to "New Address".
Private Sub CopyScheduleButton_Click()
'This procedure will copy a set of schedule records (typically a master)
'Add them to the schedule and change the address of each record to that
'of the one on the Schedule Form "Select Address" drop down
Dim NewAddress As String
NewAddress = Forms!Schedule!ComboAddressSelect.Value
DoCmd.OpenForm "CopyScheduleQuery", acFormDS ' use a query or a form based
on a query?
Recordset.MoveFirst
Do While Recordset.EOF = False 'Program Crashes here
Recordset.Address.Value = NewAddress 'Program also crashes here when
removed from loop
Recordset.MoveNext
Loop
'Copy records to Schedule Table
'?Unsure how to move these into Schedule table
'Requery Schedule
DoCmd.RunMacro ("RequerySchedule")
End Sub