Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 2003
    Posts
    37

    Unanswered: Form navigation help

    Hi I have search everywhere for help on this subject and these forums seem to have good advice!

    I have to create a project for my night class at college using access.
    As a non-windows user I haven't used this program before, but have got to grips with the basics now the problem...

    I want to create a single form with several buttons to the left and when each button is clicked it opens the form as a subform.

    Problem I have is I can only get these forms to open in new windows. I have looked at the code but having never used it am at a loss as to what to change

    Any help gratefully received

    JD

  2. #2
    Join Date
    Aug 2003
    Location
    Argentina
    Posts
    465
    Try to clarify the idea that you want.
    Saludos
    Norberto

  3. #3
    Join Date
    Nov 2003
    Posts
    1,487
    Create all your subforms onto the form which contains the buttons. Make sure each subform control has the Visible property set to False. Now, use each button on your form to set the Visible property for each corresponding subform to True and all others to False (You can create a procedure to do this). You can also set the subform size/positioning properties (Left, Top, Height, & Width) from your buttons or procedure as well. Just off the top of my head...

    Example:
    In the OnClick event of your buttons:

    Code:
    Private Sub Command1_Click ()
       'View a specific SubForm Control   
       Call OpenMySubForm(Me.mySubFormName1)
    End Sub
    
    Private Sub Command2_Click ()
       'View a specific SubForm Control 
       Call OpenMySubForm(Me.mySubFormName2)
    End Sub
    
    'etc.....
    Copy and paste this procedure into the same form code module that contains the buttons and subforms:

    Code:
    Private Sub OpenMySubForm (Sfrm as Control)
       'Close ALL SubForm Controls.
       Dim Ctrl as Control
       For Each Ctrl In Me.Controls
            If Ctrl.ControlType = acSubform Then Ctrl.Visible = False
       Next Ctrl
       'Position The SubForm Control. 
       Sfrm.Left = WhereverYouWantIt      '(in twips - 1" = 1440 twips)
       Sfrm.Top = WhereverYouWantIt      '(in twips - 1" = 1440 twips)
       Sfrm.Height = WhereverYouWantIt   '(in twips - 1" = 1440 twips)
       Sfrm.Width = WhereverYouWantIt    '(in twips - 1" = 1440 twips)
       'Make the SubForm Visible.
       Sfrm.Visible = True
    End Sub

    There ya go....

  4. #4
    Join Date
    Dec 2003
    Posts
    37
    Thanks That will do exactly what I want !

    I have tried this and think the buttons work but the subforms still stay invisible.

    Is it possible to add each set visible and set invisible in each event
    so command 1 would have set client visible, set employee invisible,set project invisible. ?

    client is the name of my first subform !

    Thanks again

    JD

  5. #5
    Join Date
    Nov 2003
    Posts
    1,487
    I'm not sure exactly what you mean. Never the less...I have now tested the code posted and all works fine. If you find that the subforms are not coming into view (visible) that it may be possible that your positioning statements (.Left, .Top, etc.) are placing the subforms into the dark zone (so to speak) of your form. Try rem'ing out the Positioning statements.

    Is it possible to add each set visible and set invisible in each event
    so command 1 would have set client visible, set employee invisible,set project invisible. ?
    Now, if you mean (by your question) whether or not you can control the visible property of each subform within the OnClick event of each command button....the answer is "Yes". But this requires a lot of unnecessary code (see the example below). Each button would need to make visible its' respecitive subform and make invisible all other subforms. This could look rather cryptic should you have lets say, 15 or 20 subforms. The choice is really up to you but better coding practice would be to keep the code as short as possible thus creating a faster, smaller, maintainable, and easier to read application.

    Code:
    Private Sub Command1_Click()
       'Hide unwanted SubForms.
       Me.Employee.Visible = False
       Me.Project.Visible = False
       'Set SubForm position.
       Me.Client.Left = 1.25 * 1440
       Me.Client.Top = 1.5 * 1440
       Me.Client.Height = 2 * 1440
       Me.Client.Width = 3.5 * 1440    
       'Set the "Client" SubForm visible.   
       Me.Client.Visible = True
    End Sub
    
    Private Sub Command2_Click()
       'Hide unwanted SubForms.
       Me.Client.Visible = False
       Me.Project.Visible = False
       'Set SubForm position.
       Me.Employee.Left = 1.25 * 1440
       Me.Employee.Top = 1.5 * 1440
       Me.Employee.Height = 2 * 1440
       Me.Employee.Width = 3.5 * 1440 
       'Set the "Employee" SubForm visible.
       Me.Employee.Visible = True
    End Sub
    
    Private Sub Command3_Click()
       'Hide unwanted SubForms.
       Me.Client.Visible = False
       Me.Employee.Visible = False
       'Set SubForm position.
       Me.Project.Left = 1.25 * 1440
       Me.Project.Top = 1.5 * 1440
       Me.Project.Height = 2 * 1440
       Me.Project.Width = 3.5 * 1440 
       'Set the "Project" SubForm visible.
       Me.Project.Visible = True
    End Sub
    See what I mean....

  6. #6
    Join Date
    Dec 2003
    Posts
    37
    Thank You so much With your help I'm slowly begining to get to grips with this have now got all subforms showing when they are ment to.

    One other thing I can't seem to get working atm on one of the forms I use a Insert statement, but I can't get it to insert into the row of the form I am editing.

    i.e it inserts into the next row. I know it needs a Insert into where in php I would use this INSERT INTO CLIENT WHERE id =$id clientclass values(1);

    but not sure how to reference variables in vb here is what I have...
    Code:
    sql = ("INSERT INTO [CLIENT](ClientClassID)VALUES (1);")
    DoCmd.RunSQL sql
    JD

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •