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

Add Calculated Records to subform 1

Status
Not open for further replies.

sterlecki

Technical User
Oct 25, 2003
181
US
I have a form/subform situation. The Main form is set up to accept input data for a calculation along with a textbox for the number of iterations.

When a cmdbutton is clicked I would like to display in the subform the calculated data based on the iteration number.
ie if iteration number is 5 then 5 lines of data would be generated.

When these data are deemed acceptable then I would like these to be written to the table that the subform is bound to.

My question is what is the best way to display and buffer these calculated multiple records? Should I use a:
1) temp table
2) or write directly to the bound table but have an undo capability if the records are not acceptable
3) some other clever idea?

would using an unbound subform as a continuous form work?

should my loop contain a line like

rstAdd.AddNew
rstAdd!field1=me.field1
rstadd.update
rst.movenext.

I've never used a form/subform situation where I am populating the many side of a one to many relationship.

Thanks for any suggestions or tips!
 
You cannot have an unbound continuous form. I think I would add the records to the bound table; this table would include, say, a flag that the user could tick to show that the record is acceptable. Unticked records could then be deleted at a suitable stage, at the end of the session for example.
 
Thanks Remou

The following code worked. I solved the QC problem by allowing record selectors on the subform allowing the user to delete any or all unacceptable records. The checkbox idea is a good one too. I will let the users decide which is easier.


Private Sub cmd_GenerateSlots_Click()

Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim rstAdd As DAO.Recordset
Dim qd As DAO.QueryDef
Dim intSlotNum As Integer
Dim dblsurfX As Double
Dim dblSurfY As Double

Set dbs = CurrentDb
Set qd = dbs.QueryDefs!qry_SurfLocsbyPod 'Query where update is going to be
Set rstAdd = qd.OpenRecordset

'Set rst = Me.RecordsetClone

'Check to see if all the Input boxes have data

If IsNull(Me![cbo_SelectPad]) Or IsNull(Me![cbo_SelectPod]) Or _
IsNull(Me!txt_surfX) Or IsNull(Me!txt_SurfY) Or _
IsNull(Me!txt_Azimuth) Or IsNull(Me!txt_WellheadSeparation) Or _
IsNull(Me!txt_SlotCount) Then
MsgBox ("Make Sure ALL Input Boxes are Completed")
Else
intSlotNum = 1
dblsurfX = Me!SurfX
dblSurfY = Me!SurfY


Do Until intSlotNum = Me![txt_SlotCount] + 1
rstAdd.AddNew
rstAdd!PodPlanID = Me!PodPlanID
rstAdd!PadName = Me!cbo_SelectPad
rstAdd!PodName = Me!cbo_SelectPod
rstAdd![PodSlot#] = intSlotNum
Debug.Print intSlotNum

rstAdd!SurfX = dblsurfX
rstAdd!SurfY = dblSurfY
rstAdd.Update

dblsurfX = dblsurfX + Me!txt_Cosine
dblSurfY = dblSurfY + Me!txt_SINE
intSlotNum = intSlotNum + 1
Loop
End If
Me.Refresh

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top