Common object for public function

M

Maarkr

I have many forms with the same controls and to advance the forms one by one;
the forms are listed in a table in viewing sequence. One control advances
the forms by looking up the form number and adding one (I made it originally
one sub for each form, then changed it to a public function in a module):

Public Function lblAdvance_Click()
On Error GoTo Err_lblAdvance_Click

Dim stDocName As String, intFormNbr As Integer

intFormNbr = DLookup("FormNo", "TableOfForms", "Form.Name =[FormName]")
intFormNbr = intFormNbr + 1
Debug.Print intFormNbr
stDocName = DLookup("FormName", "TableOfForms", "FormNo=" & intFormNbr)
Debug.Print stDocName
DoCmd.Close
DoCmd.OpenForm stDocName, acNormal

Exit_lblAdvance_Click:
Exit Function

Err_lblAdvance_Click:
MsgBox Err.Description
Resume Exit_lblAdvance_Click

End Function

I tried making a public function using this code for a combo box that you
can select the form you want to go to but it doesn't work:

Public Function CboFormSel_AfterUpdate()
On Error GoTo Err_CboFormSel_AfterUpdate

Dim stDocName As String
stDocName = CboFormSel.Value
DoCmd.Close
DoCmd.OpenForm stDocName


Exit_CboFormSel_AfterUpdate:
Exit Function

Err_CboFormSel_AfterUpdate:
MsgBox Err.Description
Resume Exit_CboFormSel_AfterUpdate

End Function

it can't find the object CboFormSel...
How do I declare it?
Is it normal to use public functions in a module to setup your own objects
that appear on many forms like menu items?? It's such a pain copying and
pasting objects and code that does the same thing on each form. Thanks.
 
J

Jeff Boyce

You've described "how" you are solving a business problem (multiple forms
listed in a table; a function that opens forms in succession).

Now, if you'll describe the "why" and "what" (tell us a bit more about the
business problem you wish to solve), the newsgroup readers may be able to
offer alternate approaches.

For example, the applications I've written still control the sequence in
which users see forms/screens, but do so without storing form names/sequence
numbers in a table. Instead, when the user is done in the first form, the
button they click takes them (automatically) to the second form...

Good luck!

--
Regards

Jeff Boyce
www.InformationFutures.net

Microsoft Office/Access MVP


Microsoft IT Academy Program Mentor
http://microsoftitacademy.com/
 
M

Maarkr

Jeff Boyce said:
business problem you wish to solve), the newsgroup readers may be able to
offer alternate approaches.

I'm tasked to improve (revise) a slide show in Access , about 25 slides
(forms), each linked to different dbs and spreadsheets on the network. This
leads into a Powerpoint slide show for the back half.
I made separate forms which I listed in a table so the owner can change the
order or add/delete forms if needed later. Each form has a button in the
corner to advance the slides one by one, and a combo box listing the slides
so you can go to any particular slide or shell to the Powerpoint show. I have
to tie in a PPt show after the Access slides cause some peeps just
won't/can't do anything but type into a text box on a slide... long term goal
is to move everything to a web format.
As I started, I was coding the Advance button (label) and combo box on the
form events, so if I worked on any form code, I had to do it 25 times. I've
done a little with pubic functions but just wanted help in getting better at
building pubic functions in modules.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top