DaveG,
There's a very easy way to do this that doesn't require the user to
rename all table columns and form fields to numbers as you have done.
All you have to do is to make sure that each field name on the foem
matches the column name in the table.
lq
Dim cmd As ADODB.command
Dim prm As ADODB.Parameter
Dim RS As ADODB.Recordset
Dim ctl As Control
Dim myID As Integer
Dim myFrm as String
Set cmd = New ADODB.command
Set cmd.ActiveConnection = CurrentProject.Connection
cmd.CommandTimeout = 0
cmd.CommandText = "StoredProcedureName"
cmd.CommandType = adCmdStoredProc
myFrm = "myFormName"
myID = Forms(myFrm).UniqueRecordID
Set prm = cmd.CreateParameter("myParameterName", adInteger,
adParamInput, , myID)
cmd.Parameters.Append prm
Set RS = cmd.Execute()
If Not RS.EOF Then
For Each ctl In Forms(myFrm).Controls
If ctl.ControlType = acTextBox Then ctl.value =
RS(ctl.Name)
Next ctl
End If
RS.Close
Set RS = Nothing
Set prm = Nothing
Set cmd = Nothing
Set ctl = Nothing
Dave G @ K2 wrote:
Quote:
Thanks Tom
>
It didn't work for the field value, but curiously I got it to work for
the labels. Here's a snippet of the code that I'm testing for 2 fields
>
For i = 1 To 2
Forms![frmCADI].Controls("lbl" & CStr(i)).Caption =
GetCADIText(i)
Forms![frmCADI].Controls(i) = rs![i]
Next i
>
So the fields are called 1 and 2 and the associated field labels are
called lbl1 and lbl2. If I comment out the second line then it works
fine - I see 2 field labels as expected. But with the second line in it
errors with a 3265 - item not found in this collection.
>
If I use:
For i = 1 To 2
Forms![frmCADI].Controls("lbl" & CStr(i)).Caption =
GetCADIText(i)
Next i
Forms![frmCADI]![1] = rs![1]
Forms![frmCADI]![2] = rs![2]
>
then it works great !!
>
Any ideas
Dave