Using a Button to activate Subform.

Hi All

I need some help again!!

I did this a few months back but now can not remember how I did it!!

I have a Main Form of Member details working well and this has a SubForm showing eMail to and from this Member.

Now I want to add a Button to the Main Form that opens a window on top of the Main Form and this window contains a second Subform with some other information. I have created the table for the second Subform and put the Button on the Main Form but can not remeber how I got it all to work!!

Any help would be appreciated!!

LO Base 3.6.5.2 linking to MySQL 5.1.55

IanW
Pretoria RSA

Hi Ian,

Not sure if this is what you need, but it works for me. I got it from the
Web.

On the Events tab of my button under 'Mouse button pressed', I connect to
the sub, OpenfMembers(). If you substitute your form name in place of
"fMembers" I think it should work for you too.

Sub OpenfMembers(oEvent AS Object)

      OpenForm("fMembers")

End Sub

Sub OpenForm(FormName AS String)

      With ThisDatabaseDocument.currentcontroller

           If Not .isConnected Then

                .Connect

           End if

      End With

      ThisDatabaseDocument.FormDocuments.getByName(FormName).open

End Sub

Noel

Thanks Noel

Hi Ian,

Not sure if this is what you need, but it works for me. I got it from the
Web.

On the Events tab of my button under 'Mouse button pressed', I connect to
the sub, OpenfMembers(). If you substitute your form name in place of
"fMembers" I think it should work for you too.

Sub OpenfMembers(oEvent AS Object)

       OpenForm("fMembers")

End Sub

  Sub OpenForm(FormName AS String)

       With ThisDatabaseDocument.currentcontroller

            If Not .isConnected Then

                 .Connect

            End if

       End With

       ThisDatabaseDocument.FormDocuments.getByName(FormName).open

End Sub

I tried this and it seems to remind me that I used something like this before!!

However when I try it and "press the button" on my Main Form it takes me to the Macro Edit window and I can not close this as it says "Basic is still running"!!

Should I be linking to my Table or to my Form?? Otherwise any other ideas??

Thanks a lot

IanW
Pretoria RSA

Hi Ian,

Is there an error message showing in the Macro Edit window?

You should be able to close the window after clicking on the Stop Macro
button, (a red circle with the white 'X' in it, in the middle of the
controls up the top.)

Does the sub Form work if you run it manually? (Double click on the Form
name.) If so then your button should call the sub that calls the Form - I
take it that the Table is connected to the Form.

If none of this helps, could you post the modified code you are attempting
to run?

Noel

Thanks Noel

I appreciate the 'come-back'!!!

Hi Ian,

Is there an error message showing in the Macro Edit window?

I didn't get one before but now when I try again I get
                 "BASIC runtime error.
                 An exception occurred
                 Type:com.sun.container.NoSuchElementException
                 Message:StoryTable"

You should be able to close the window after clicking on the Stop Macro button, (a red circle with the white 'X' in it, in the middle of the controls up the top.)

Mine (PClinuxOS 2013.2) is a red circle with a white square and it has no effect!!
The only way to stop it is to close my Main Form and then I can stop it.

Does the sub Form work if you run it manually? (Double click on the Form name.) If so then your button should call the sub that calls the Form - I take it that the Table is connected to the Form.

Yes - it runs fine when I double-Click the Form Icon.

If none of this helps, could you post the modified code you are attempting to run?

My Database is called "FedSaints" and I have 3 Tables - "Members", "eMails" and "StoryTable".
In my Forms area I have 2 Forms - My Main Form called "Members" (which includes a SubForm from the "eMail" Table) and a Form called "Story", (This is the Form I'm wanting to pop-up over the main Form with the Button)

This is what I put in the Button Macro...

Sub OpenStoryTable(oEvent AS Object)

       OpenForm("Story")

End Sub

  Sub OpenForm(FormName AS String)

       With ThisDatabaseDocument.currentcontroller

            If Not .isConnected Then

                 .Connect

            End if

       End With

       ThisDatabaseDocument.FormDocuments.getByName(FormName).open

End Sub

Thanks for the help

IanW
Pretoria RSA

Hi Ian,

I would suggest that you check on the actual name of your form -

Open the Form in Edit mode
Right Click on any field
Choose Form
Make sure the General tab is selected
Whatever is showing in the Name field is the name the system will look for
If it's showing something other than 'Story', then that is your problem
If not, then I don't know.
It's odd that the error message is saying 'StoryTable' rather than 'Story'

You may need to set a breakpoint in Sub OpenStoryTable(oEvent AS Object)
and then single step through the code to see exactly where it throws the
error. That may give you a clue as to what is happening.

Good luck!
Noel

Thanks again Noel.

Let's give this one more 'go-around'!!

Hi Ian,

I would suggest that you check on the actual name of your form -
Open the Form in Edit mode
Right Click on any field
Choose Form
Make sure the General tab is selected
Whatever is showing in the Name field is the name the system will look for
If it's showing something other than 'Story', then that is your problem
If not, then I don't know.
It's odd that the error message is saying 'StoryTable' rather than 'Story'

OK - I guess you are right here!! My name of the new Form is "Story" NOT "StoryTable" (That's the name of the Table!!). So I changed that. I also checked on my Main Form that I call "Members" but the System seems to call it "MainForm" - so which is right?? Changing this however made no difference!!

You may need to set a breakpoint in Sub OpenStoryTable(oEvent AS Object) and then single step through the code to see exactly where it throws the error. That may give you a clue as to what is happening.

I'm afraid you are way ahead of me here - I've no idea how to do this!!

So - last of all can we look at your Macro again.../[My comments to the right of each line//]/

Sub OpenStoryTable(oEvent AS Object) - - -/[Is it right to open the Table here or should it be the Form?]/
       OpenForm("Story") - - -/[My Form is called "Story" but checking on this shows an empty Name field??]/
End Sub

  Sub OpenForm(FormName AS String) - - - /[I have not changed anything below this line - correct??]/
       With ThisDatabaseDocument.currentcontroller
            If Not .isConnected Then
                 .Connect
            End if

       End With
       ThisDatabaseDocument.FormDocuments.getByName(FormName).open

End Sub

Thanks for the help

IanW
Pretoria RSA

Hi Ian,

This is starting to get a bit cluttered so I've used blue for m
y
comments this time. See below.

Thanks again Noel.

Let's give this one more 'go-around'!!

Hi Ian,

I would suggest that you check on the actual name of your form -

  Open the Form in Edit mode
Right Click on any field
Choose Form
Make sure the General tab is selected
Whatever is showing in the Name field is the name the system will look
for
If it's showing something other than 'Story', then that is your problem
If not, then I don't know.
It's odd that the error message is saying 'StoryTable' rather than
'Story'

OK - I guess you are right here!! My name of the new Form is "Story" NOT
"StoryTable" (That's the name of the Table!!). So I changed that. I also
checked on my Main Form that I call "Members" but the System seems to call
it "MainForm" - so which is right?? Changing this however made no
difference!!
In the Form's General tab (as described in my last post), the Name shown
there is what the system uses. You can change this to anything you like,
but whatever you make it will be the "official" name, and needs to be used
whenever Macro code refers to that Form, (as in this instance where you
want to open the Story Form).

You may need to set a breakpoint in Sub OpenStoryTable(oEvent AS Object)
and then single step through the code to see exactly where it throws the
error. That may give you a clue as to what is happening.

I'm afraid you are way ahead of me here - I've no idea how to do this!!

Don't worry about this just now - you may not need it.

So - last of all can we look at your Macro again...* [My comments to the
right of each line**]*

Sub OpenStoryTable(oEvent AS Object) - - -* [Is it right to open the
Table here or should it be the Form?]*

As with naming a Form, you can call a Sub anything you like. The name
has no bearing on what happens inside the Sub, but it is better to have a
name that tells you what the Sub does.

I would suggest that you *not* change it now, but once you have got the
button working you could consider changing it to - OpenStoryForm(oEvent AS
Object).
In that case you will also need to edit the button on the Members Form so
that it calls OpenStoryForm(), not OpenStoryTable().

What this Sub does is pass the name "Story" to the OpenForm Sub which does
the opening. Once the Form is opened, it then opens the "StoryTable"

      OpenForm("Story") - - -* [My Form is called "Story" but checking on
this shows an empty Name field??]*
I think we have found the problem!

If in the Story Form's General tab the Name is blank, then you need to
change it to "Story" to match the name given in this Sub. This lines up
with the error message you got that said "NoSuchElementException". In
other words the system was looking for a Form named "Story", but in fact it
was named blank!

End Sub

Sub OpenForm(FormName AS String) - - - * [I have not changed anything
below this line - correct??]

Thanks once again Noel - I appreciate your persistence!!

I have deleted my original 'StoryForm' and recreated it. I then found the both my 'MembersForm' and 'StoryForm' were called "MainForm" by the system so I renamed each as I had titled them. Both work perfectly from the Base Start Window.

I then reworked the Macro as below and set it to the Button on the Members page ..

Sub OpenStoryForm(oEvent AS Object)
       OpenForm("StoryForm")
End Sub

Sub OpenForm(FormName AS String)
       With ThisDatabaseDocument.currentcontroller
            If Not .isConnected Then
                 .Connect
            End if
       End With
       ThisDatabaseDocument.FormDocuments.getByName(FormName).open
End Sub

Now when I press the button I get the error "BASIC runtime error. Incorrect property value" and it highlights the line in red above.

Greatly appreciate this assistance!!

IanW
Pretoria RSA

Hi Ian,

I was puzzled as to why the code works for me, but not for you.
Often the problem line is the one below the highlighted one, so I did some
googling on ThisDatabaseDocument and found this URL -
http://listarchives.libreoffice.org/global/users/msg13132.html

In the last post of the thread, Drew points out that the code containing
ThisDatabaseDocument needs to be embedded in the database itself, (in
the.odb file).

With your application opened, if you go to the LibreOffice Basic Macros
page, (a quick way in is to use Alt T B O M), you will see -
My Macros
  ..
  Standard
..
<Your database name>. odb (in my case U3A.odb)
  Standard
    Main

In your case I think you have probably put the code in the My Macros
section which is mainly for general Subs that could be used in any
database. If that is so, then you need to move the two Subs to the .odb
section. If you have never added code here, you should find an empty Main
Sub. Just add your two Subs below that. This is the place to put all Subs
that apply only to the current database.

It was more luck than good management that I happened to put the Subs in
the right place! But now I know to watch out for this.

Hopefully this will get your button working.

Noel