passing string as a form

S

Steve

I have an Access DB and it is frustrating that when there are multiple forms
open, there is not an easy way of having a selection list which allows the
user to choose which form they want to view (bring to front/on top/etc). I
looked on the web for some code to create/manage this, but I couldn't find
anything.

So I am creating my own code.

I have successfully made it work. When a user opens a form, it adds the
form to a temporary table for the user's session. When a form is closed, it
removes that record from the table. The table is displayed as a pop-up form
on the left of the screen. When a user selects the NAME of the screen they
want to see (i.e. set focus and effectively bring to the front), I am having
trouble passing the form name (stored as text) to the VB commad which will
set the focus to that form.

For example:

Customers
Transactions
Accounts

When the user clicks on the text "customers", there is a hidden control
which has the form name "sfrm_customers" and I am trying to pass this form
name to do the following:

Forms![FORMNAME].setfocus 'FORMNAME should be replaced with sfrm_customers
in teh example above

Since "sfrm_customers" is stored as TEXT, I am not sure how to pass that
information so that it can be intrepreted as a FORM.

The alternative is that I have a module with Hard-codes form names. This
seems like an archaic method.

Am I making this harder than it should be? Help?

-Stephen
 
A

Albert D. Kallal

As you gain ms-access experience, you will quickly learn that with any
amount of programming experience, you find that there is a collection
available for what you need...

To reference a open form, you can go:
s = "frmcustomers"


forms(s)!lastname

the above would be of course the equivalent of

forms!frmCustomers!LastName


So, I guess what I am saying is that there is a built in collection of
*open* forms that is already available, and it is kind of surprising you not
used it in your daily normal coding, let alone a attempt to offer some list
of forms....

Anytime you need to reference a set of "controls" on a form, or a collection
of forms, or just about EVERYTHING IN ALL OF MS-ACCESS IS based on a
collection.

Collections are fundamental GLUE that holds together your appcation, and
anytime you reference a reocrdset, forms, or just about anything, you are in
fact using a collection. So, the simple answer here is to use the forms
collection. I guess I trying to install that ms-access is built around
collections, you want to be aware of this for when you start writing code.


forms.Count will always = the number of forms open.....

So, you have a ready made list of open forms at all times.....

Dim i As Integer
For i = 0 To Forms.Count - 1

Debug.Print Forms(i).Name

Next i

'You can also use the for each, and again, this is for just about
everhting in ms-acces...

Dim f As Form

For Each f In Forms

Debug.Print f.Name

Next f

Remember, even fields in a reocrdset retuned is a collection .....

dim rst as dao.RecordSet


set rst = currentdb.OpenReocrdSet("select * from tblCustomers")

debug.print rst("LastName")

-- fields is the default colleciton, so, in fact, you could go

debug.print rst.Fields("Lastname").value

(and, value is the default property of that field collection, so, in both
the above cases...I could use .value, but we often leave out .value since it
is the default).

So, collections are your friend, and there is one for just about everything
you do....open forms, the controls on a form...etc......

Collections = life blood of ms-access.....
 
A

Albert D. Kallal

By the way, have you considered using the "windows in taskbar" option?

If you set the above option..then all windows will display in the windows
task bar..and the user can use those for switching between forms....
 

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