Results 1 to 7 of 7
  1. #1
    Join Date
    Nov 2002
    Location
    UK
    Posts
    12

    Exclamation Unanswered: please help me someone.....

    Hi

    I have a main form called frmParent and a subform called frmSub. on frmParent I have a field called txtmodcode. this value changes dependant on a value chosen from a combo box.

    on frmsub I have a tabctl which has 4 pages and a commend button. I want the focus to be set to a page number depending on the value in frmparent!txtmodcode.

    sub_onclick_btn()
    if forms!frmParent!txtmodcode = "U1PS" or forms!frmParent!txtmodcode = "U1PST" Then

    tbctl.SetFocus
    docmd.GoToPage 0

    elseif forms!frmParent!txtmodcode = "U1AHM" or forms!frmParent!txtmodcode = "U1ALM" Then

    tbctl.SetFocus
    docmd.GoToPage 1

    end if
    end Sub

    This code gives me an error message saying that this method is not available.

    what am i missing??

    thanks in advance

  2. #2
    Join Date
    Jun 2002
    Location
    Toronto, Canada
    Posts
    7
    Scully:

    If I understand correctly, you just want one of the 4 tabs to have the "focus" depending on the entry in a specific text box.

    Tab Controls cannot receive focus. One way you could do it, though, would be to set the visible property of all tabs to false. Then, in your code, depending on the entry in the text box, set the visible property of that particular page to true (remembering that page numbering starts at 0 and not 1).

    I just tried it out real quick just on the Load Event of the form and it worked. Off the top of my head I don't know if it is best to reset the visible property back to false whenever the form loads or whether it will automatically do that because of the default settings you put in design view. But if you play around you'll see what happens.

    Anyway, hope this helps out a bit.

    DT

  3. #3
    Join Date
    Nov 2002
    Location
    Kansas City, MO
    Posts
    2

    RE:please help me someone.....

    I believe I understand what you are trying to accomplish. You want a selection on your main form to go directly to a tab on a subform of frmParent. I created a sample that I will upload here if my explanation makes no sense. Just let me know.

    Because frmSub is a subform on frmParent, you must reference both frmParent and frmSub in any code that you use, even in the subform itself.

    So the code will go something like this:

    Private Sub btn_Click()
    If Forms.frmparent.txtmodcode = "U1PS" Or Forms.frmparent.txtmodcode = "U1PST" Then

    Forms.frmparent.subForm.Form.page0.SetFocus

    ElseIf Forms.frmparent.txtmodcode = "U1AHM" Or Forms.frmparent.txtmodcode = "U1ALM" Then

    Forms.frmparent.subForm.Form.page1.SetFocus

    End If
    End Sub


    When you look at the code, you will notice that after Forms!frmParent it says subForm instead of frmSub. This is because subForm refers to the name given the subform when you put it onto the form frmParent.

    One last note, I created my example using Access XP but converted to Access 97 and the code still worked. I'm not sure what version you are using.

    Good Luck.

  4. #4
    Join Date
    Nov 2002
    Location
    UK
    Posts
    12

    Question

    i tried both above methods, thanks, but still no joy. on the current event of the parent form I have me!frmSub!tab.visible = false and on the after update event of the parent form i put this code:

    Dim frmsubMarksUG1 As Form
    Dim frmsubMarksUG2 As Form
    Dim frmsubMarksUG3 As Form
    Dim frmsubMarksUG4 As Form
    If Me![year] = 1 Then Me![frmSub].SourceObject = "frmsubMarksUG1"
    If Me![year] = 2 Then Me![frmSub].SourceObject = "frmsubMarksUG2"
    If Me![year] = 3 Then Me![frmSub].SourceObject = "frmsubMarksUG3"
    If Me![year] = 4 Then Me![frmSub].SourceObject = "frmsubMarksUG4"




    Me![frmSub].SourceObject.Repaint
    If Me![ModuleCode] = "U1PS" Or Forms!frmDataEntry.Form![ModuleCode] = "U1PST" Or Forms!frmDataEntry.Form![ModuleCode] = "U1SPS" Then
    Me![frmSub].page0.Visible = True
    ElseIf Me![ModuleCode] = "U1AHM" Or Forms!frmDataEntry.Form![ModuleCode] = "U1ASS" Or Forms!frmDataEntry.Form![ModuleCode] = "U1AFT" Then
    Me![frmSub].page1.Visible = True
    ElseIf Me![ModuleCode] = "U1AMU" Then
    Me![frmSub].Page2.Visible = True
    ElseIf Me![ModuleCode] = "U1ALM" Then
    Me![frmSub].Page3.Visible = True
    End If

    but i get an error message saying access does not support this method or object and points to the page0. properties.

    will it not work because i alternate the source object of the frmsub depending on an entry in a control on the parent form?

    have i missed something else now???

  5. #5
    Join Date
    Jun 2002
    Location
    Toronto, Canada
    Posts
    7
    Scully

    You are very close on the visible part of your code - just your syntax to referring to the sub-form is incorrect. You first need to refer to the Main Form, then the Sub Form, then the Sub Form Control. (pay careful attention to 'bangs' and 'dots')

    I my example I have a simple Text Box (Text3) and a command button (Command5) on my main form. Depending on the value typed into the text box, I can make the pages on my tab control become visible or not. I named my two pages PageA and PageB in the properties (my comment in my earlier post about numbering starting at 0 does not apply here and I just managed to confuse myself by referring to it!)

    I've used Select Case to get away from what could possibly be a lengthy if statement, but if you feel more comfortable, your ifs would do it also.

    Select Case Me.Text3.Value
    Case "PageA"
    Forms![frmParent]![frmSub].Form![PageA].Visible = True
    Case "PageB"
    Forms![frmParent]![frmSub].Form![PageB].Visible = True
    Case Else
    Forms![frmParent]![frmSub].Form![PageA].Visible = False
    Forms![frmParent]![frmSub].Form![PageB].Visible = False
    End Select

    Hope this helps out a bit.

    DT

  6. #6
    Join Date
    Nov 2002
    Location
    UK
    Posts
    12
    thanks all for you help, I got round it by adding a setfocus command to each if statement



    If Forms!frmDataEntry.Form![ModuleCode] = "U1PS" Or Forms!frmDataEntry.Form![ModuleCode] = "U1PST" Or Forms!frmDataEntry.Form![ModuleCode] = "U1SPS" Then
    Me.Page0.SetFocus
    Me.Page0.Visible = True
    Me.Page1.Visible = False
    Me.Page2.Visible = False
    Me.Page3.Visible = False
    ElseIf Forms!frmDataEntry.Form![ModuleCode] = "U1AHM" Or Forms!frmDataEntry.Form![ModuleCode] = "U1ASS" Or Forms!frmDataEntry.Form![ModuleCode] = "U1AFT" Then
    Me.Page1.SetFocus
    Me.Page1.Visible = True
    Me.Page0.Visible = False
    Me.Page2.Visible = False
    Me.Page3.Visible = False
    ElseIf Forms!frmDataEntry.Form![ModuleCode] = "U1AMU" Then
    Me.Page2.SetFocus
    Me.Page2.Visible = True
    Me.Page0.Visible = False
    Me.Page1.Visible = False
    Me.Page3.Visible = False
    ElseIf Forms!frmDataEntry.Form![ModuleCode] = "U1ALM" Then
    Me.Page3.SetFocus
    Me.Page3.Visible = True
    Me.Page0.Visible = False
    Me.Page1.Visible = False
    Me.Page2.Visible = False
    End If

    got there in the end

    thanks again

  7. #7
    Join Date
    Jun 2002
    Location
    Toronto, Canada
    Posts
    7
    Glad you got it to work out in the end.

    DT

Posting Permissions

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