Google: Access VBA save record from unbound form.
Here is one example of saving a single record: http://www.blueclaw-db.com/unbound_access_forms.htm
In your case you want to save 20 records. Can have the sample code repeated 20 times, just change each instance to reference the appropriate set of controls. An alternative is loop structure which is definitely trickier. Here is an example from my project that builds a very long string from 8 sets of 5 unbound controls:
Code:
With Me
For i = 1 To 8
strReport = strReport & _
Pad(i, "R", 15) & _
Pad(Format(Forms(.Name).Controls("tbxSpgAvg" & i), "0.000"), "R", 19) & _
Pad(Format(Forms(.Name).Controls("tbxAbsAvg" & i), "0.00"), "R", 9) & _
Pad(Format(Forms(.Name).Controls("tbxLbfAvg" & i), "0"), "R", 38) & _
Pad(Format(Forms(.Name).Controls("tbxNAvg" & i), "0"), "R", 11) & _
Pad(Format(Forms(.Name).Controls("tbxFloAvg" & i), "0"), "R", 7) & _
" " & vbCrLf
Next
End With
Your loop would instead incorporate the code in the referenced link. An alternative to code that opens recordset and adds record to the recordset is an INSERT sql action which inserts record directly to table:
Code:
For i = 1 to 20
CurrentDb.Execute "INSERT INTO tablename(fieldname1, fieldname2) " & _
"VALUES('" & Forms(Me.Name).Controls("controlnameA" & i) & "', #" & Forms(Me.Name).Controls("controlnameB" & i) & "#)"
Next
I am showing apostophe delimiters for text values and # for date values. Numbers don't need delimiters.
Note that for these looping examples the sets of controls must be similarly named and have a numeric suffix.
And if you are not already aware, if names have spaces, special characters, punctuation (underscore is exception) in them or are reserved words, enclose in [].