I am attempting to populate a form with buttons with button captions which have been assigned through code.
buttons names are btn1, btn2, btn3...etc
The code indicates a query - Query1 which gives a dataset which is populated from the products table with product name and price.
The problem I have encountered is I am unable to change from btn1 to btn2 and so on from within the loop, can anyone shed any light on this.
Expand|Select|Wrap|Line Numbers
- Private Sub Form_Load()
- Dim db As Database
- Dim qdf As QueryDef
- Dim prm As Parameter
- Dim rs As Recordset
- Dim strProduct As String
- Dim strPrice As String
- Set db = CurrentDb
- Set qdf = db.QueryDefs("Query1")
- For Each prm In qdf.Parameters
- prm.Value = Eval(prm.Name)
- Next prm
- Set rs = qdf.OpenRecordset(dbOpenDynaset)
- rs.MoveFirst
- Do Until rs.EOF
- strProduct = rs![Product]
- strPrice = rs![Price]
- btn1.Caption = strProduct & " " & strPrice
- rs.MoveNext
- Loop
- End Sub