Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need code more generalized and shorter 1

Status
Not open for further replies.

kpal29

Technical User
Feb 8, 2003
147
DK
I have an unbound form called MainMenu that I use for a Main Menu.

Down the left side I have labels that correspond to different forms. Next to these I have an unbound subform named Child2.

When a user clicks on a label, the sourcobject of Child2 changes to the corresponding form name and that form appears in the subform. And the label backcolor turns white.

Currently there are 13 labels. I have achieved the above with some cumberson and long-winded code which will be difficult to edit when I need to add/change/delete labels.

Below is a sample (just one of the labels) that I use to change the child2's sourceobject:

Private Sub Import_Click()
Me.Child2.SourceObject = "ProfitLossImport"
Call allprocesses (calls function that changes backcolor)
End Sub

I have this attached to each labels ON CLICK event.

The code that changes the backcolor looks like this for each label:

Sub HighlightLabels()
If Me.Child2.SourceObject = "ProfitLossImport" Then
Me.Import.BackColor = 16777215
Me.Accruals.BackColor = 12632256
Me.UndoImp.BackColor = 12632256
Me.ZipFiles.BackColor = 12632256

Me.BuiltInReport.BackColor = 12632256
Me.CustomReport.BackColor = 12632256
Me.ExceptionReport.BackColor = 12632256
Me.CM2Report.BackColor = 12632256

Me.ImportTable.BackColor = 12632256
Me.AggregateTable.BackColor = 12632256
Me.ChartofAccountTable.BackColor = 12632256
Me.ProfitCenterTable.BackColor = 12632256
Me.YearTable.BackColor = 12632256
______________________________________________________
I tried using (CurrentControl = screen.activecontrol
Child2.sourcobject = CurrentControl) concept but I don't think labels can be in an active state? Please help!
 
First off (I am using Access 97 btw), Create a query with the following SQL...

Code:
SELECT MSysObjects.Name AS FormName
FROM MSysObjects
WHERE (((MSysObjects.Name)<>"frmMenuForm" And (MSysObjects.Name)<>"frmMain") AND ((MSysObjects.Type)=-32768));

And call it 'qryForms'

This will return all forms in the database except two which we are going to create for our menus....

Next create a continuous form with the above query as its record source. Turn off Allow Data Entry, Allow Edits, Allow Additions and Allow Deletions. Also set Scrollbars to vertical and turn off navigation, record selectors and dividing lines. Call this form frmMenuForm

Add a textbox with a transparent background that is locked. Set its Control Source to FormName

This form will now give you a scrollable list of forms (excluding this form) when you select one, it will turn white.

I also included the following On_Current event code

Code:
Private Sub Form_Current()
    txtFormName.SetFocus
    txtFormName.SelStart = 0
    txtFormName.SelLength = 0
    With Form_frmMain
        .Caption = txtFormName
        .frmsubForm.SourceObject = txtFormName
    End With
End Sub

where txtFormName is my textbox...

frmMain is next...

Create a form (frmMain) and drag our frmMenuForm onto it.

Next drag one of your other sub forms onto frmMain.

Save it and run it and (hopefully) this will do the trick.

Let me know if you need any further help

 
If you've sorted the changing of source objects, and it's only about toggling the backcolors of the labels, try the following:

In the .Tag property of each of the label controls, place a number from 1 to 13 (or you could change the names to lbl1 thru lbl13, for that sake).

Then in each label click event, pass only the correct number, and try something like this:

call the sub
[tt]call togglecontrol(1)[/tt]

the sub
[tt]private sub togglecontrols(lNum as long)
dim ctl as control
for each ctl in me.controls
if ctl.controltype=aclabel then
if len(ctl.tag & vbnullstring)>0 then
if ctl.tag=lnum then
ctl.backcolor=16777215
else
ctl.backcolor=12632256
end if
end if
end if
next ctl
end sub[/tt]

- typed not tested, you'll find some more samples of form control looping in faq702-5010

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top