C
Can
I have a continuous subform (modal pop-up) in a database. I want to copy
some of the fields into a temporary table. As the user does data entry they
are in the last record in the subform. I want to move the record selector to
the top but the code I have has been tempermental. Any ideas?
Here's the two versions of code I've tried:
VERSION 1
Dim dbs As Database
Set dbs = CurrentDb
Dim rstSubform As DAO.Recordset
Dim rstCurrent As Recordset
Set rstCurrent = dbs.OpenRecordset("_Current_Location", dbOpenDynaset)
tmpValue = "No"
rstCurrent.MoveFirst
Dim lng As Integer
lng = 0
Set rstSubform = Me!zzzAdd_Location_Tanks_Split.Form.RecordsetClone
If rstSubform.RecordCount > 0 Then
rstSubform.MoveFirst
Do While lng < Me!zzzAdd_Location_Tanks_Split.Form.SelTop And
Not rstSubform.EOF
rstCurrent.AddNew
rstCurrent![_Current_Location_Location_ID] = Location_ID.Value
rstCurrent![_Current_Location_To_Tank_ID] =
Forms![Add_Location_Split]![zzzAdd_Location_Tanks_Split]![Location_Tanks_To_Tank_ID]
rstCurrent![_Current_Location_From_Tank_ID] =
Forms![Add_Location_Split]![zzzAdd_Location_Tanks_Split]![Location_Tanks_From_Tank_ID]
rstCurrent![_Current_Location_TotalMales] =
Forms![Add_Location_Split]![zzzAdd_Location_Tanks_Split]![Location_Tanks_TotalMales]
rstCurrent![_Current_Location_TotalFemales] =
Forms![Add_Location_Split]![zzzAdd_Location_Tanks_Split]![Location_Tanks_TotalFemales]
rstCurrent![_Current_Location_TotalUnknown] =
Forms![Add_Location_Split]![zzzAdd_Location_Tanks_Split]![Location_Tanks_TotalUnknown]
rstCurrent.Update
rstSubform.MoveNext
lng = lng + 1
Loop
End If
Set rstSubform = Nothing
rstCurrent.Close
VERSION 2
Dim dbs As Database
Set dbs = CurrentDb
Dim rstSubform As DAO.Recordset
Dim rstCurrent As Recordset
Set rstCurrent = dbs.OpenRecordset("_Current_Location", dbOpenDynaset)
tmpValue = "No"
rstCurrent.MoveFirst
Set rstSubform = Me!zzzAdd_Location_Tanks_Split.Form.RecordsetClone
rstSubform.MoveFirst
Do Until rstSubform.EOF
rstCurrent.AddNew
rstCurrent![_Current_Location_Location_ID] = Location_ID.Value
rstCurrent![_Current_Location_To_Tank_ID] =
Forms![Add_Location_Split]![zzzAdd_Location_Tanks_Split]![Location_Tanks_To_Tank_ID]
rstCurrent![_Current_Location_From_Tank_ID] =
Forms![Add_Location_Split]![zzzAdd_Location_Tanks_Split]![Location_Tanks_From_Tank_ID]
rstCurrent![_Current_Location_TotalMales] =
Forms![Add_Location_Split]![zzzAdd_Location_Tanks_Split]![Location_Tanks_TotalMales]
rstCurrent![_Current_Location_TotalFemales] =
Forms![Add_Location_Split]![zzzAdd_Location_Tanks_Split]![Location_Tanks_TotalFemales]
rstCurrent![_Current_Location_TotalUnknown] =
Forms![Add_Location_Split]![zzzAdd_Location_Tanks_Split]![Location_Tanks_TotalUnknown]
rstCurrent.Update
If (rstSubform.RecordCount = rstSubform.AbsolutePosition + 1) Then
Exit Do
Else
rstSubform.AbsolutePosition = rstSubform.AbsolutePosition + 1
End If
Loop
Set rstSubform = Nothing
rstCurrent.Close
some of the fields into a temporary table. As the user does data entry they
are in the last record in the subform. I want to move the record selector to
the top but the code I have has been tempermental. Any ideas?
Here's the two versions of code I've tried:
VERSION 1
Dim dbs As Database
Set dbs = CurrentDb
Dim rstSubform As DAO.Recordset
Dim rstCurrent As Recordset
Set rstCurrent = dbs.OpenRecordset("_Current_Location", dbOpenDynaset)
tmpValue = "No"
rstCurrent.MoveFirst
Dim lng As Integer
lng = 0
Set rstSubform = Me!zzzAdd_Location_Tanks_Split.Form.RecordsetClone
If rstSubform.RecordCount > 0 Then
rstSubform.MoveFirst
Do While lng < Me!zzzAdd_Location_Tanks_Split.Form.SelTop And
Not rstSubform.EOF
rstCurrent.AddNew
rstCurrent![_Current_Location_Location_ID] = Location_ID.Value
rstCurrent![_Current_Location_To_Tank_ID] =
Forms![Add_Location_Split]![zzzAdd_Location_Tanks_Split]![Location_Tanks_To_Tank_ID]
rstCurrent![_Current_Location_From_Tank_ID] =
Forms![Add_Location_Split]![zzzAdd_Location_Tanks_Split]![Location_Tanks_From_Tank_ID]
rstCurrent![_Current_Location_TotalMales] =
Forms![Add_Location_Split]![zzzAdd_Location_Tanks_Split]![Location_Tanks_TotalMales]
rstCurrent![_Current_Location_TotalFemales] =
Forms![Add_Location_Split]![zzzAdd_Location_Tanks_Split]![Location_Tanks_TotalFemales]
rstCurrent![_Current_Location_TotalUnknown] =
Forms![Add_Location_Split]![zzzAdd_Location_Tanks_Split]![Location_Tanks_TotalUnknown]
rstCurrent.Update
rstSubform.MoveNext
lng = lng + 1
Loop
End If
Set rstSubform = Nothing
rstCurrent.Close
VERSION 2
Dim dbs As Database
Set dbs = CurrentDb
Dim rstSubform As DAO.Recordset
Dim rstCurrent As Recordset
Set rstCurrent = dbs.OpenRecordset("_Current_Location", dbOpenDynaset)
tmpValue = "No"
rstCurrent.MoveFirst
Set rstSubform = Me!zzzAdd_Location_Tanks_Split.Form.RecordsetClone
rstSubform.MoveFirst
Do Until rstSubform.EOF
rstCurrent.AddNew
rstCurrent![_Current_Location_Location_ID] = Location_ID.Value
rstCurrent![_Current_Location_To_Tank_ID] =
Forms![Add_Location_Split]![zzzAdd_Location_Tanks_Split]![Location_Tanks_To_Tank_ID]
rstCurrent![_Current_Location_From_Tank_ID] =
Forms![Add_Location_Split]![zzzAdd_Location_Tanks_Split]![Location_Tanks_From_Tank_ID]
rstCurrent![_Current_Location_TotalMales] =
Forms![Add_Location_Split]![zzzAdd_Location_Tanks_Split]![Location_Tanks_TotalMales]
rstCurrent![_Current_Location_TotalFemales] =
Forms![Add_Location_Split]![zzzAdd_Location_Tanks_Split]![Location_Tanks_TotalFemales]
rstCurrent![_Current_Location_TotalUnknown] =
Forms![Add_Location_Split]![zzzAdd_Location_Tanks_Split]![Location_Tanks_TotalUnknown]
rstCurrent.Update
If (rstSubform.RecordCount = rstSubform.AbsolutePosition + 1) Then
Exit Do
Else
rstSubform.AbsolutePosition = rstSubform.AbsolutePosition + 1
End If
Loop
Set rstSubform = Nothing
rstCurrent.Close