Save All Record On Subform

sinau

New member
Local time
Today, 20:40
Joined
Jul 26, 2023
Messages
3
hi, im try to save all record on subform to tabel but only first record saved, an this my code :

Code:
Public Sub DetailSaved()

Dim Rs As DAO.Recordset
Dim subFrm As Access.Form

Set subFrm = Me.[FTSLIPSEC].Form
Set Rs = subFrm.RecordsetClone
Do While Not Rs.EOF

CurrentDb.Execute "INSERT INTO [tclmshare] (fscregno,fscaccid,fscslpno,fscsleno,fscproid,fscpronm,fscshare,fscedsec,fscamont,fsctamnt,fscvochr)" & _
                  "select '" & Me!FTSLIPSEC.Form.txt_regno & "',acc_id, slip_no, endt_num, prof_id, prof_name, share, cedsec, '" & Me!FTSLIPSEC.Form.txt_valsc & "',(share * '" &                     Me!FTSLIPSEC.Form.txt_valsc & "' /100 ) AS '" & Me!FTSLIPSEC.Form.txt_tvlsc & "','" & Me!FTSLIPSEC.Form.txt_notsc & "' from QTSLIPSEC " & _
                  "Where slip_no ='" & Me!FTSLIPSEC.Form.slip_no & "' and endt_num =" & Me!FTSLIPSEC.Form.endt_num & ";"
Rs.MoveNext
Loop

End Sub
 
Last edited by a moderator:
use Bound form, so you don't need to use VBA.
saving will be done automatically.
 
If you are trying to insert multiple records into tclmshare from query QTSLIPSEC (whatever they are), then why not do it from an Append Query? You have criteria to constrain the set of values - based on form values (?), and you could launch from a button on your form, after committing any change to data on the form. (ie. not dirty). Assuming that you are sure that you would not create duplicate records in tclmshare.
 
"' and endt_num =" & Me!FTSLIPSEC.Form.endt_num & ";"
Wrong!!!
In my opinion you should take the argument from current record of open Recordset - not from current record of subform.
SQL:
... "' and endt_num =" & Rs!endt_num & ";"
 
thank you for the input and suggestions from everyone in this forum, it turns out that the error that occurred came from me stating the first field was primary while the data I entered was detailed data, so only 1 record entered, after I removed the primary... .all data can be entered, thank you all for the support. case closed
 

Users who are viewing this thread

Back
Top Bottom