Dynamically allocated "buttons" (1 Viewer)

DCinFRANCE

Registered User.
Local time
Today, 20:13
Joined
Oct 21, 2017
Messages
21
First, I want to thank again those that posted to my last question. I value my time, and certainly appreciate those that give me their time.

Now, for something interesting.

I have a continuous form. There is a field on the form lines from which I would like to allocate its value to the caption of a button on the line, and then deferentially, based on the value, load a form when clicked...each value representing a corresponding and different form that needs to be loaded.

Say I have 3 lines, and the field values are A, B and C. On each respective line, I want a button captioned A, B and C, and when you click the button, frmA loads, frmB loads or frmC loads respectively.

Just some background...I'm trying to demonstrate that this somewhat complex database can be realized without resorting to coding, save some small and inescapable macros using Access' macro builder. That, and I haven't coded anything since the late 80's and know nothing about VBA or whatever. Just the same, I can read the code and understand roughly what it does -- and I have seen seen code examples that have clued me into what I need to do (kinda like being able to read a foreign language and get the gist of what it says but not being able to speak it).
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 02:13
Joined
May 7, 2009
Messages
19,230
Yiu cant assign different caption on the button since there is only one button on continuous form. You can however open different forms depends on the field where your button is.
 

DCinFRANCE

Registered User.
Local time
Today, 20:13
Joined
Oct 21, 2017
Messages
21
Thanks, but I don't think you quite understand. I can put a button in the detail on a form that is set to continuous forms, and place a button on it such that it appears in each line of the form. Further, I can drive the contents of the underlying form based on values on the particular line it is in. In one case, I have exactly this, which when clicked opens a popup form with details based on the contents in its line. However, the button is always labeled the same, and it always loads the same form. I want to load different forms based on the content of the line.
 

isladogs

MVP / VIP
Local time
Today, 19:13
Joined
Jan 14, 2017
Messages
18,211
Arnelgp is correct though there are ways around it.

What you are seeing in the continuous form is many instances of the same button.
You could use VBA to set a caption but it would be the same for each copy of the button.

However it should be possible for the button code to select a form based on the selected record.

I do have continuous forms with buttons on each 'row'. For example:
- a delete button to delete that record
- a button to open a report filtered for that recordings
- a button to open a photo of the person in the selected record
However the caption is identical for each 'row'



What you COULD do, is a create a pseudo button with its own caption
In the screenshot, you'll see the Category field has several different captions & colours.
If I click on one of those it opens a form filtered to the calendar event selected
So you could add a field with appropriate formatting to look like a button & add code to that which opens the form(s)

However, much easier to place a button beside the continuous form that will use the selected record to open another form
 

Attachments

  • Capture.PNG
    Capture.PNG
    48.5 KB · Views: 160
Last edited:

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 02:13
Joined
May 7, 2009
Messages
19,230
yes i understand what you are saying.
but as you can see in design view
of your continuous form, there is
only one button. it get multiplied
by the number of visible records, but
it does not change the fact that
there is only one button. so as far as
renaming each button, NO possible.
you can just make the caption more meaningful
say, "Open Form".
regarding the action on OnClick event of
the button, you can have Different form
depends on PK key (usually ID). so you must
test the ID value, then launch the correspoding
form, eg:

Private Sub button_Click()
SELECT CASE Me.ID
CASE Is = 1
DoCmd.OpenForm "FormForID_1", acNormal
CASE Is = 2
DoCmd.OpenForm "FormForID_1", acNormal
CASE ELSE
MsgBox "Form not available"
END SELECT
End Sub
 

Gasman

Enthusiastic Amateur
Local time
Today, 19:13
Joined
Sep 21, 2011
Messages
14,259
Hmm, I read this as the o/p wanting a button in the continuous form for each of the text boxes?

His example had controls A, B & C and wanting 3 buttons in the row captioned A, B or C ?
Then if B is clicked the value in textbox B is used to open form B ?
 

DCinFRANCE

Registered User.
Local time
Today, 20:13
Joined
Oct 21, 2017
Messages
21
Thanks everyone. No Gasman, that's not it. Its basically as the others have responded.

On click of a single button, if the field1 value is A, load frmA, else if field1 value is B, load frmB, else if field1 value is C, load frmC else there is no form for the value.

Thanks for the code attempt, arnelgp. I assume a little debugging would lead to the line for the second case to

DoCmd.OpenForm "FormForID_2", acNormal
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 02:13
Joined
May 7, 2009
Messages
19,230
there will be no need for a SELECT CASE
statement if you setup the Forms
name to the correspoding ID in the record.
supposing you set your form so as
the suffix is the ID number:

DoCmd.OpenForm "FormForID_" & Trim(Me.ID), acNormal
 

Users who are viewing this thread

Top Bottom