Macro to open form + pass on value from current form

Hi All,

I have a form that has bookID as a unique key. I want to have a button
that is to open a second form and do the following:

(1) search for the bookID in another table (Series);
(2) If bookID does not exist in Series, create a new record that has the
bookID and open another form and passes the bookID to that form so I can
enter the appropriate info.

Guidance appreciated.

Best,
Joel

Hi Joel,

I have a form that has bookID as a unique key. I want to have a button
that is to open a second form and do the following:

(1) search for the bookID in another table (Series);
(2) If bookID does not exist in Series, create a new record that has the
bookID and open another form and passes the bookID to that form so I can
enter the appropriate info.

My own take on this, as I had something similar setup a long time ago,
was to have a button that activated a macro which :

- checked whether a value existed in another table via a parameterized
query,
- if the ID didn't exist, constructed and fired an INSERT statement to
insert a new value into that table (either automatically if it was
autoincrement, or using a previous last_insert_id() function to query
the id counter and add 1 to it to create my new counter value ;
- then return the inserted value and display it to the user via a
message box.

Alternatively, I guess I could've caused a second form to open up after
successful completion of the INSERT statement, but that isn't what I needed.

Not quite sure why you need to open a whole set of other forms though,
as the value you obtain for BookID could be inserted programmatically
without going through forced UI steps (unless that is what you want for
some particular reason)

Alex

My own take on this, as I had something similar setup a long time ago,
was to have a button that activated a macro which :

- checked whether a value existed in another table via a parameterized
query,

Do you have an example of how to do this? The online documentation is
quite scarce for base :-/

- if the ID didn't exist, constructed and fired an INSERT statement to
insert a new value into that table (either automatically if it was
autoincrement, or using a previous last_insert_id() function to query
the id counter and add 1 to it to create my new counter value ;
- then return the inserted value and display it to the user via a
message box.

Alternatively, I guess I could've caused a second form to open up after
successful completion of the INSERT statement, but that isn't what I needed.

Not quite sure why you need to open a whole set of other forms though,
as the value you obtain for BookID could be inserted programmatically
without going through forced UI steps (unless that is what you want for
some particular reason)

Well the button is basically "Book is Part of Series" - this opens a new
form "Series" which allows me to then either select a series that's
already entered, or if it's a new series that I'm just starting, allows
me to create a new series entry and attaches the bookID to that series.

Thanks Alex - been told you're one of the go to heroes in the db
community. I appreciate the help as this is all somewhat new to me.

Best,
Joel

Hi Joel,

- checked whether a value existed in another table via a parameterized
query,

Do you have an example of how to do this? The online documentation is
quite scarce for base :-/

Unfortunately, this was in a previous life of mine, and I didn't get to
keep the code or the ODB file :-/

I can only suggest the following that might help you further :

- Robert Grosskopf's Guide to Base (this is currently the documentation
projects official Base Guide / Handbook) - ther emight well be something
in there for you

- Roberto Benitez' book on using OOBasic for programming Base for
OpenOffice.org ;

- Andrew Pitonyak's experiences of using Basic with Base in his PDF book.

Also, I'm pretty certain that the kind of question you're asking has
been posted on the OpenOffice.org forum - there are some very capable db
people over there, that have cried tears of sweat and blood over Base in
the past, and continue to do so today, offering help to the lonely,
needy, and lost :wink:

Well the button is basically "Book is Part of Series" - this opens a new
form "Series" which allows me to then either select a series that's
already entered, or if it's a new series that I'm just starting, allows
me to create a new series entry and attaches the bookID to that series.

Ah, OK, I understand a bit better now. Definitely read through the Base
Handbook / Guide, and especially Robert's Media database ODB file.
Additionally, I really would suggest a trawl through the OOo forum.

Personally, I'm kind of moving away from LO Base as a front end - for
me, it needs to behave reliably over even minor version changes, and
experience has shown that, unfortunately, the fast pace of code change
in the LO project doesn't allow that to be the case.

Good luck,

Alex

Hi All,

I have a form that has bookID as a unique key. I want to have a button
that is to open a second form and do the following:

(1) search for the bookID in another table (Series);
(2) If bookID does not exist in Series, create a new record that has the
bookID and open another form and passes the bookID to that form so I can
enter the appropriate info.

Guidance appreciated.

Best,
Joel

This can be done without macro using stand-alone forms, hyperlink button
and a criteria table.

1) [Example #1] Filter/Search with Forms (leveraging SubForms)

https://forum.openoffice.org/en/forum/viewtopic.php?f=100&t=42845

2) [Tutorial] Standalone Forms / Switchboard:

And, when you can solve a problem without a macro, that is generally the better path :slight_smile:

And, when you can solve a problem without a macro, that is generally the
better path :slight_smile:

And for most of the rest we have: