473,320 Members | 2,024 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Dynamic buttons on Access Form

9
If any assistance can be provided would be appeciated.

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
  1. Private Sub Form_Load()
  2.  
  3.  
  4. Dim db As Database
  5. Dim qdf As QueryDef
  6. Dim prm As Parameter
  7. Dim rs As Recordset
  8.  
  9. Dim strProduct As String
  10. Dim strPrice As String
  11.  
  12. Set db = CurrentDb
  13. Set qdf = db.QueryDefs("Query1")
  14.  
  15.     For Each prm In qdf.Parameters
  16.             prm.Value = Eval(prm.Name)
  17.     Next prm
  18.  
  19. Set rs = qdf.OpenRecordset(dbOpenDynaset)
  20.  
  21.  
  22.             rs.MoveFirst
  23.  
  24.         Do Until rs.EOF
  25.  
  26.         strProduct = rs![Product]
  27.         strPrice = rs![Price]
  28.  
  29.         btn1.Caption = strProduct & " " & strPrice
  30.  
  31.             rs.MoveNext
  32.  
  33.         Loop
  34.  
  35. End Sub
  36.  
May 18 '07 #1
2 1210
MMcCarthy
14,534 Expert Mod 8TB
You have posted in the Articles section.

I am moving this question to the Access forum.

ADMIN
May 18 '07 #2
JConsulting
603 Expert 512MB
If any assistance can be provided would be appeciated.

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
  1. Private Sub Form_Load()
  2.  
  3.  
  4. Dim db As Database
  5. Dim qdf As QueryDef
  6. Dim prm As Parameter
  7. Dim rs As Recordset
  8.  
  9. Dim strProduct As String
  10. Dim strPrice As String
  11.  
  12. Set db = CurrentDb
  13. Set qdf = db.QueryDefs("Query1")
  14.  
  15.     For Each prm In qdf.Parameters
  16.             prm.Value = Eval(prm.Name)
  17.     Next prm
  18.  
  19. Set rs = qdf.OpenRecordset(dbOpenDynaset)
  20.  
  21.  
  22.             rs.MoveFirst
  23.  
  24.         Do Until rs.EOF
  25.  
  26.         strProduct = rs![Product]
  27.         strPrice = rs![Price]
  28.  
  29.         btn1.Caption = strProduct & " " & strPrice
  30.  
  31.             rs.MoveNext
  32.  
  33.         Loop
  34.  
  35. End Sub
  36.  

how about

Expand|Select|Wrap|Line Numbers
  1. Dim db As DataBase
  2. Dim qdf As QueryDef
  3. Dim prm As Parameter
  4. Dim rs As Recordset
  5. Dim I As Long
  6. Dim strProduct As String
  7. Dim strPrice As String
  8.  
  9. Set db = CurrentDb
  10. Set qdf = db.QueryDefs("Query1")
  11.  
  12.     For Each prm In qdf.Parameters
  13.             prm.Value = Eval(prm.Name)
  14.     Next prm
  15.  
  16. Set rs = qdf.OpenRecordset(dbOpenDynaset)
  17.     rs.MoveLast
  18.     rs.MoveFirst
  19.  
  20.     For I = 1 To rs.RecordCount - 1
  21.  
  22.         strProduct = rs![Product]
  23.         strPrice = rs![Price]
  24.  
  25.         Me("btn" & I).Caption = strProduct & " " & strPrice
  26.  
  27.    Next I
  28.    rs.Close
  29.    Set rs = Nothing
  30.  
May 18 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Craig Keightley | last post by:
I have a page that has n number of radio groups (yes/No) how can i prevent the form being submitted if more than one radio group is not selected? By default all radio groups are unchecked ...
5
by: Lyn | last post by:
Hi, I hope someone can help. I have a main form which mostly fills the Access window. In the bottom half of this form I have a tab control to display various types of data related to the main...
6
by: MikeY | last post by:
Hi Everyone, Does anyone know where I can get my hands on a sample with source code of a simple dynamic button control in C# Windows form. I am looking for a sample that uses a class library...
1
by: Klom Dark | last post by:
I've got a weird problem going on - I've got a table of dynamically created buttons. Each button has the X/Y value of the buttons position in the table assigned to it's CommandArgument property and...
1
by: andrei | last post by:
Hi Group, I have an aspx form with a variable number of buttons added dynamically, with id's like b01, b02, b03... Whenever I click one of these buttons, the form is posted back. I need to...
3
by: WebBuilder451 | last post by:
I have a series of dynamic link buttons created based upon a datareader. I've added a click event and it calls the sub ok: example: "while loop through the reader" Dim ltrCtrl As New...
7
by: Fred White | last post by:
Hi, I have a desktop application that uses an array of dynamic buttons in a class. I would like on button-click to change the text in a static text box on the form. The problem is that that when...
8
by: George Meng | last post by:
I got a tough question: The backgroud for this question is: I want to design an application works like a engine. After release, we can still customize a form by adding a button, and source code...
22
by: Saul | last post by:
I have a set of radio buttons that are created dynamically, after rendered I try loop thru this set by getting the length of the set, but I keep getting an error stating the element is undefined. I...
3
by: creative1 | last post by:
Here is how you create a complex data report that involves parent and child commands and you can update information at runtime. Its pretty straight forward to work with simple queries; however,...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.