Creating Tab's at Run Time?

OneRandomStone

Registered User.
Local time
Today, 08:47
Joined
Jul 16, 2003
Messages
12
I'm currently working on a form, which contains quite a few subforms. It has been suggested (or should i say forcefully suggested) that I use tab controls for a certain subform.

Here's the catch.

I need to be able to add X number of tab's depending on the number of records retreived from a table once the master / child links are set.

I have two main tables...

Customers (i'll keep it short)

cuID(unique key, foreign key)
cuName
cuNum
cuFax

Machines

mcID(unique key)
cuID(foreign key)
mcMachine
mcCost

So... each customer can have an X number of machines (maximum is 5)...

What i want to do is create tabs for each machine they have (at run time)...

Can anybody Help?
Thanx.
 
Hi

I think what would be better is a main form and a subform. There are loads of posts on here about this subject but in brief:


In this case the Main form displays customer data i.e name address etc. This form is almost always columnar (keeping things simple).

The subform is tabular or datasheet. This will display a list of all the computers owned by the customer.

If you do it this way you don't really need to have tabs.


Basically create a main form(columnar) based on the first table (use a query) create a second form(tabular) based on the machine table(use a query).

Open the mainform and insert an subform object from the toolbar.
The wizard should start.

Select the machineform as the source, the link between your keys should be suggested for you by the wizard

When you move records on the mainform the subformwill display the data for the next customer

See example

Hope that helps

Chris
 

Attachments

...

Thnxs for the info CJ,

That's pritty much what i did in the first layout of my form... i had
a mainform containing all the customer information and under a machine heading, a subform linked through cuID which displayed all the computers associated with that customer. Everything was fine until i showed it to prospective users...who kicked up a stink :( -- they don't like using the |< < > >| * controls (not windows enough for them). Thats why they wanted me to make it create a new tab for each computer, with the computer name as the caption so they can easily select the one they want.

:rolleyes:
:confused:

Think you can help? I've tryed microsoft's help pages, to no avail as usual! (anybody managed to get anything useful of their support site?)

Cheers,
Andy
 
Hi

B***dy users!.

This really isn't how a database works. Forgive me if i'm telling you something you already know but the whole point of the machine table is that you can add as many machines for each user as you need there really is no simple way to start adding and deleting controls on a form at run time i.e when the user is using the form. You are going to get some serious headaches later on if you do manage to do what you want viz data integrity.

If you can't convince them that they are ludite idiots who should let you do things properly, then tell them to stick it up their A*** :D

Only kidding but it might be worth telling them what they are asking for is not what Access was designed to do.


Any way this may be of some use but tread with caution.


I'm not sure how this is going to work then. You have to scroll through the user records in order to display the computers that the user has regardless of how you actually display the computer information. The only way to avoid the <> arrows is to use a continous form to display the user data and on the change event of the continous form you do a requery of the subform.


Any way. This is only an idea sorry don't have time to actually try it.


1) Create 1 tabcontrol with (5?) pages each with the a sub form on each ( subforms should be columnar with no navigation buttons or addnew record button (could have delete button i guess).

2) Create code to count number of records available on the form

something like (if using access 2000 or newer ,select microsoft dao 3.6 (maybe 3.51 in xp) from tools>addins in module)

You may need this on the form open event as well as the form current event


Dim rst(1) as dao.recordset
Dim db as dao.database
Dim Varbookmark as variant
Dim Tabcount as Integer

set db = currentdb

' create a rst of all the computers owned(?) by the customer

set rst(0) = db.openrecordset( Select machines.* from machines WHERE (((machine.cuid)=" & me.cuid & "));")

' hide the tab controls

Me.TabCtl0.Pages(0).Visible = true
Me.TabCtl0.Pages(1).Visible = true

' Display blank form +tab if new customer

if rst(0).recordcount = 0 then

Me.TabCtl0.Pages(0).Visible = true

exit sub

end if


' if there is a record then make the tab visible

do until tabcount = rst(0).recordcount
Me.TabCtl0.Pages(tabcount).Visible = true

' create a copy of the subforms recordset
'Not sure about this forms!frmmain.. syntax you'll need to check this out.

set rst(1) = forms!frmmain!Forms("subform" & tabcount+1).recordsetclone

rstmove = 0
rst(1).movefirst

' move the record to the equivalent tab number i.e tab0 will display record 1


do until rstmove = tabcount
rst(1).movenext
rstmove = rstmove+1
loop

'Not sure about this forms!frmmain.. syntax you'll need to check this out.

' make the sub forms rst position = to the copy of the rst(1)
forms!frmmain!Forms("subform" & tabcount+1).Bookmark = rst(1).Bookmark

set rst(1) = nothing
tabcount = tabcount +1

loop


' tabcount will be 6 if all 5 computers are used
'if not you will need to display the next computer + tab and a new record


if tabcount < 6 then

Me.TabCtl0.Pages(tabcount).Visible = true

forms!frmmain!Forms("subform" & tabcount+1).addnew

end if

set rst(0) = nothing
set rst(1) = nothing
set db = nothing


This is in no way correct or perfect it's just the basis of an idea. But i strongly suggest that you talk to the user and explain how access actually works you never no your luck.

;)

Good luck

Chris
 
Last edited:
Ugh!

Hi & Thnx Again Chris! :rolleyes:

I've been in disscusion with the main supervisor for those 'little darling users! Ugh...anyway, i managed to persuade her that although it does state in my job discription, my need to create such systems, i ain't a myrical worker and nor is access!

I've read your codin, and it looks pritty sound... i think i've seem it in somebody's vb prog not so long ago, but like you said - it's better to stick with what your good at...

So, < > buttons will stay, and the 'users' will have to put there claims foward for the 'Repetative Strain Injury' induced by them having to put in a few extra yards with their mouse...

Thanks for your Help Chris,

Cheers....
 

Users who are viewing this thread

Back
Top Bottom