PDA

View Full Version : Opening a form dynamically based on a table value


ABC123

rmcgaffic
04-26-2008, 01:45 PM
How do you get A5 to accept as a form name the value from a field in a table?

I have created a new form with only one A5V9 pushbutton control, which executes the code below:


tbl = table.open("tblMenu")
tbl.fetch_first()
Dim mSelectedForm As C
mSelectedForm = tbl.FORM_ID
msgbox(mSelectedForm)
'msgbox displays: frmA
f=form.load(mSelectedForm)
f.show()
f.activate()

When the button is clicked, the following error message is received:


Error: OnPush line: 14
f=form.load(mSelectedForm)
Object does not support requested interface

While the above simply demonstrates what appears to me to be a fairly serious problem, the code below shows all the approaches I have attempted to get A5V9 to dynamically open a form based on a value in table, not "hardwiring" it in code.

Here's my "real" code, and the question boils down to how to get AlphaFive to think its dealing with a form name that must be in quotes. I even tried changing the table field value from frmA to "frmA", that is putting " " around the value, and it failed.


If doIt then
Dim mSelectedForm As C
Dim mSelectedNode As N

mSelectedNode = ctTree1.Selected()
msgbox("Selected node "+str(mSelectedNode))

mSelectedForm = ctTree1.NodeCargo(mSelectedNode)
msgbox(mSelectedForm)
'The message box correctly displays: frmA

'Case 1: This works
'f=form.load("frmA")

'Case 2: This works
'mSelectedForm = "frmB"
'f=form.load(mSelectedForm)

'Case 3: This does NOT work
'mSelectedForm = """ + mSelectedForm + """
'msgbox(mSelectedForm)
'here's what the message box displays: + mSelectedForm +
'f=form.load(mSelectedForm)

'Case 4: This does NOT work
'mSelectedForm = '"' + mSelectedForm + '"'
'This fails the code syntax check as an empty expression
'msgbox(mSelectedForm)
'f=form.load(mSelectedForm)

'Case 5: This does NOT work
'mSelectedForm = "'" + mSelectedForm + "'"
'This fails the code syntax check as missing or invalid keyword
'msgbox(mSelectedForm)
'f=form.load(mSelectedForm)

f.show()
f.activate()

doIt=.f.

end if

Two days ago, I reported success in creating an hierarchical menu using a third party Tree control. I have worked through all the issues with that control, and was actually feeling quite good about having accomplished something non-trivial with A5, but just as I was ready to post my code to the code library, I hit what hopefully is not a fatal bump.

MS Access has no problems opening a form based on the value of a variable. Does anyone have any suggestions on what workaround might allow A5V9 to do this also?

Thanks,
Bob
Pittsburgh

rmcgaffic
04-26-2008, 01:53 PM
Steve Workings posted the following response to prematurely submitted response that I want to link to my complete thread. Thanks, Steve. Let me give it a try.

Almost. The alltrim() is your key here.


tbl = table.open("tblMenu")
tbl.fetch_first()
tbl = table.open("tblMenu")
tbl.fetch_first()

Dim mSelectedForm As C
mSelectedForm = alltrim(tbl.FORM_ID)
msgbox(mSelectedForm)
'msgbox displays: frmA

f = form.view(mSelectedForm)

Al Buchholz
04-26-2008, 01:53 PM
Steve Working's suggestion (http://msgboard.alphasoftware.com/alphaforum/showpost.php?p=455967&postcount=2) is related to this duplicate/completed posting..

Bob

I see the previous posting was incomplete. Those darn enter keys sometimes happen at the east appropriate times.... ;) At least they do for me...

The message board does have an edit process that is available for about an hour after a posting is made. Next time you make a post and look at the result, you'll notice the edit button (next to the quote button) will be there for a while.

rmcgaffic
04-26-2008, 01:58 PM
Steve, you are the MAN!!!

It works flawlessly!

Al,

I didn't realize I had submitted my premature post until I submitted my complete post. I know you can edit, but is it possible to delete a post?

Some forums have moderators that are really sensitive to double postings.

Thanks to you both,

Bob McGaffic
Pittsburgh

Tom Cone Jr
04-26-2008, 02:29 PM
Bob, the trailing blanks Alpha inserts to maintain fixed width fields in each record have bitten all of us. Some, including myself, have forgotten about this more than once! The darn spaces are just too hard to see! -- tom

Al Buchholz
04-26-2008, 02:42 PM
Al,

I didn't realize I had submitted my premature post until I submitted my complete post. I know you can edit, but is it possible to delete a post?

Some forums have moderators that are really sensitive to double postings.

Thanks to you both,

Bob McGaffic
Pittsburgh

No problem.. I wasn't sure if you knew about edit. About the only thing for deleting that a normal user can do is wipe out the content of the post and put a 'Sorry about that' in it's place.....

Or find Lenny and have him delete it.

Fortunately, the sensitivity level of the board is moderate not hyper.

btw, nice work with the tree control....

rmcgaffic
04-26-2008, 07:14 PM
All,

Everything now appears to be working correctly. I have documented this project in a 16 page MS word document available in the Code Archive with the title "How to create a dynamic hierarchical menu"

Bob McGaffic
Pittsburgh

rmcgaffic
04-26-2008, 07:15 PM
All,

Everything now appears to be working correctly. I have documented this project in a 16 page MS word document, including all code and screen prints of control settings, available in the Code Archive with the title "How to create a dynamic hierarchical menu"

Bob McGaffic
Pittsburgh

ogmcheck
08-26-2010, 05:47 PM
Glad you got it working. Where else besides Alpha do you get the creator/programmer to do a video to show you how to perform a task? Try this with Microsoft or some other software. Selwyn (and many others at Alpha) should be nominated for customer service of the year award!

Thanks for all of your responses to our issues.