* Loop through and populate unbound fields on a form from a table...
Public Sub FillUnboundForm()
On error resume next
Dim db As Database
Dim rst As Recordset
Dim rfld As DAO.Field
On Error Resume Next
Set db = CurrentDb
Set rst = db.OpenRecordset("select * from mytable", dbOpenDynaset, dbSeeChanges)
With rst
If .EOF Then
Else
For Each rfld In rst.Fields
Me(rfld.Name) = rfld
Next
End If
End With
End Sub
* Loop through and save unbound fields on a form to a table...
Public Sub saveUnboundForm()
On error resume next
Dim db As Database
Dim rst As Recordset
Dim rfld As DAO.Field, myfield
On Error Resume Next
Set db = CurrentDb
Set rst = db.OpenRecordset("select * from mytable",dbOpenDynaset, dbSeeChanges)
With rst
If .EOF Then
Else
For Each rfld In rst.Fields
rst.Edit
rfld = Me(rfld.Name)
rst(Me(rfld.Name)) = Me(rfld.Name).Value
rst.update
Next
End If
End With
End Sub
* Loop through controls on a form and construct an SQL statement...
private sub butgo_click()
dim ctl as control
dim strSQL as string
for each ctl in me.controls
if typeof ctl is checkbox then
if ctl.value = true then
strSQL = strSQL & ctl.name & ", "
end if
end if
next
strsql = "SELECT " & left$(strSQL, len(strSQL) - 2) & " FROM mytable"
end sub