Setting values on Controls of Subform

S

s_wadhwa

Hi,

Can anyone can answer my query that how we can set Data on Subform from

a recordset.


when I'm trying to set it like


Set frm1 = Forms("fsubroomsdept")
Set frm1.Recordset = rstQry
str1 = rstQry!BuildingName
Do While rstQry.EOF <> True
For Each ctl1 In frm1
If TypeOf ctl1 Is TextBox Or TypeOf ctl1 Is ComboBox Then
Select Case ctl1.Name
Case "BuildingName"
ctl1.SetFocus
ctl1.Value = str1
Case "buildingNumber"
ctl1.SetFocus
ctl1.Value = str2
Case Else
Exit Sub
End Select
End If
Next
rstQry.MoveNext
Loop


it throws an error saying that you can't set a value its read only.


please help any comments/ suggestions are welcome.


thanks,
Shalini
 
D

Douglas J. Steele

You can't assign a value to a combo box.

I don't understand why you're looping through the controls, though. Rather
than looping through all of the controls, simply use:

Set frm1 = Forms("fsubroomsdept")
Set frm1.Recordset = rstQry
str1 = rstQry!BuildingName
Do While rstQry.EOF <> True
frm1.Controls("BuildingName") = str1
frm1.Controls("buildingNumber") = str2
rstQry.MoveNext
Loop

(of course, I'm assuming that either BuildingName or BuildingNumber is a
combo box, so one of those won't work)

Better yet, don't use a recordset either: simply run an Update query to
populate the table. It's almost always faster to use SQL than a recordset.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top