I have a form bound to a table with a click button to add records to the table. It has been working fine and up to now most of the fields are initialized to Null values when the new rec is created. A change to call a routine has been added to the click routine along the likes of the following:
AddRec_Click()
results = GetStuff() ' tried it here
With Me.RecordsetClone
results = GetStuff() ' and here
.AddNew
...initialize fields....
results = GetStuff() ' and here
...some fields= results
.Update
End With
End Sub
The change which has been added requires that the same table be scanned and various results tallied which are used to initialize some of the fields on a new record. A separate routine was created to do this scanning which although it DOES access the same table, all activity is done using a separate recordset and all is read-only - just gathering info from a selected subset of records - no change to table. The called routine looks like the following:
Public Function GetStuff()
Dim rst as Recordset, strSQL As String
...create SQL string (simple SELECT * FROM Table WHERE
fields = criteria)
Set rst = CurrentDb.OpenRecordset(strSQL)
Do Until rst.EOF
...loop through records gathering info & counting
...gather info
Loop
GetStuff = results ' return counts, etc
End Function
The problem is that inserting the call to GetStuff() anywhere in the click routine somehow causes a loss of record position to create the new record. I've put it right after entry to the routine, just after the With clause, down in the list of initialization assignments and anywhere it is put, I get a "No Current Record" error when trying to create the new record.
Is there anything obviously wrong with this approach?
Thanks in advance for your help,
farmgrown
AddRec_Click()
results = GetStuff() ' tried it here
With Me.RecordsetClone
results = GetStuff() ' and here
.AddNew
...initialize fields....
results = GetStuff() ' and here
...some fields= results
.Update
End With
End Sub
The change which has been added requires that the same table be scanned and various results tallied which are used to initialize some of the fields on a new record. A separate routine was created to do this scanning which although it DOES access the same table, all activity is done using a separate recordset and all is read-only - just gathering info from a selected subset of records - no change to table. The called routine looks like the following:
Public Function GetStuff()
Dim rst as Recordset, strSQL As String
...create SQL string (simple SELECT * FROM Table WHERE
fields = criteria)
Set rst = CurrentDb.OpenRecordset(strSQL)
Do Until rst.EOF
...loop through records gathering info & counting
...gather info
Loop
GetStuff = results ' return counts, etc
End Function
The problem is that inserting the call to GetStuff() anywhere in the click routine somehow causes a loss of record position to create the new record. I've put it right after entry to the routine, just after the With clause, down in the list of initialization assignments and anywhere it is put, I get a "No Current Record" error when trying to create the new record.
Is there anything obviously wrong with this approach?
Thanks in advance for your help,
farmgrown