Results 1 to 14 of 14
  1. #1
    Join Date
    Feb 2004
    Location
    UK
    Posts
    246

    Unanswered: Intelligent menu's

    Hi,
    The current system that I'm working on has about 30 forms, some of these forms can be accessed from more than one form. Currently there is an exit button on each form that closes the form and returns to a set form.

    My question is how can I get the form to close and return to the form that opened it, for example

    Form A can open form C, normally when the user exits form C they press the form exit button which closes form C and reopens form A or more correctly brings form A into focus. But form R can also open form C, but if the user has got to form C via form R and they press the close button on form C the form goes back to form A. In this case it should go back to form R.
    What I want to do is for the system to detirmine which form called the current form and return to the calling form.

    Regards
    John

  2. #2
    Join Date
    Apr 2004
    Location
    Kingsland, Georgia
    Posts
    231
    when you open form c from form r, why not write form r's name in form c's .tag property? then as you close form c, reopen or focus on formc.tag.

  3. #3
    Join Date
    Feb 2004
    Location
    UK
    Posts
    246
    Hi,
    Thanks very much for the reply and apologies for n0t getting back to you, been unable to get onto the forum

    Can you explain a bit more about the Tag property and how I get it to change form one form to the other (if I need to)

    Regards
    John

  4. #4
    Join Date
    Apr 2004
    Location
    Kingsland, Georgia
    Posts
    231
    sure. the .Tag property is a property to store extra info. so here's how to use it:
    you're in form R. run a
    Code:
    DoCmd.OpenForm "frmC"
    and then
    Code:
    frmC.Tag = Me.Name
    . then close or hide form r. when the user closes form c,
    Code:
    DoCmd.OpenForm me.tag
    since for c's .tag contains form Rs name, it should open form R.
    of course, this is gonna require a few lines of code to every single form you've got, but it should do what you want it to. good luck.

  5. #5
    Join Date
    Feb 2004
    Location
    UK
    Posts
    246
    Hi,
    Thanks for the quick response, but................................

    I'm really struggling to get my head around this, obviously being really thick doesn't help

    Can I just go over a simple scenario with 2 different forms being able to call 1 form.
    As before 2 forms A or R can call form C. Opening form C is no problem but how do I tell form C that it was Form A or R that opened it? and then having closed form C how do I re-focus on Form A or A dependiing on which opened form C?

    So in one of the 2 forms that can call form C I enter a bit of code after the DoCmd.OpenForm "formC"
    FormC.Tag = Me.Form

    Then in form C I enter in code after the
    DoCmd.Close
    DoCmd.OpenForm Me.tag

    Anyway I've done this but have a couple of problems. The form closes and goes to the correct calling form but
    On opening form C from either form A or R I get and error message of
    "Object required" I can only do OK and the form opens

    On exiting the form I get an error message of
    "The expression you entered refers to an object that is closed or doesn't exist"

    Any ideas where the issues lie

    Regards and thanks for the help

    John

  6. #6
    Join Date
    Apr 2004
    Location
    Kingsland, Georgia
    Posts
    231
    you're close, man. your line of code after the DoCmd.OpenForm "formC" should be
    formC.Tag = Me.Name instead of Me.Form. The rest of it seems like it should work. I can't actually code it in right now to test it, but I will when I get the chance. Try switching that line of code and see if it works.

  7. #7
    Join Date
    Feb 2004
    Location
    UK
    Posts
    246
    Hi,
    Thanks for the sugesstion, tried the change of code with Name instead of Form but still getting the same message

    Thanks for all you time, its really appreciated

    Regards
    John

  8. #8
    Join Date
    Apr 2004
    Location
    Kingsland, Georgia
    Posts
    231
    alright, man. here it is. i'm doing this with two forms.
    Form1
    Code:
    Private Sub cmdButton_Click()
        Dim frm As Form
        DoCmd.OpenForm "Form4", acNormal
        Set frm = [Forms]!Form4
        
        frm.Tag = Me.Name
        DoCmd.Close acForm, "Form1", acSaveNo
    
        set frm = Nothing
    End Sub
    And then
    Form4
    Code:
    Private Sub Command0_Click()
        DoCmd.OpenForm Me.Tag, acNormal
        DoCmd.Close acForm, "Form4", acSaveNo
    End Sub
    this works perfectly for me. good luck. lemme know how it turns out.

  9. #9
    Join Date
    Feb 2004
    Location
    UK
    Posts
    246
    Hi,
    Great news your last post solved the problem, thank you very much, I can now use this in a number of other forms that are opened from more than one source.

    One small little issue has cropped up, on one of the calling forms, there is a button that before it opens the required form has a custom dialog box that pops up allowing the user to further filter his criteria. When using this box it opens the form OK but when trying to return to the calling form I get the error message "The action requires a Form Name argument".
    What I want to happen is for the form to go back to the form and ignore the pop up dialog box.

    Regards
    John

  10. #10
    Join Date
    Feb 2004
    Location
    UK
    Posts
    246
    I've been playing around with this and can't seem to get a result

    I've put the following code onto the popup form as follows

    Private Sub Find_Policies_Click()
    On Error GoTo Err_Find_Policies_Click

    Dim stDocName As String

    stDocName = "Int_search_mco2"
    DoCmd.RunMacro stDocName

    Set frm = Policies_frm
    frm.Tag = Me.[Forms]!Policies_frm

    Set frm = Nothing


    Exit_Find_Policies_Click:
    Exit Sub

    Err_Find_Policies_Click:
    MsgBox Err.Description
    Resume Exit_Find_Policies_Click

    End Sub

    But I get a "Type mismatch" error, although it still goes into the form, but I can't exit the form back to the original form, not the pop-up. The error message is as follows "The action or method requires a Form Name argument"

    Can anyone point me in the right direction as to where I'm going wrong

    Edit, sorry what I should add to help is that the Form "Policies_frm" is called by the form "Intsearch_frm" which is a pop-up form that is called by the form "Select_records". When I get to "Policies_frm" I want to exit straight to "Select_records".

    Regards
    John
    Last edited by Sticker; 05-05-04 at 08:15.

  11. #11
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Hi

    I've only had a quick scoot through the threads here so forgive me if I miss the point. The type mismatch is probably because you are trying to assign a form to a string variable (i.e. the .Tag property accepts a string value only).

    If I understand what you are trying to do, you might want to change

    frm.Tag = Me.[Forms]!Policies_frm

    to

    frm.tag = me.name (me.name is the name of the form your code is in, and is a string value).

    also, nosing at your code you might want to look up about Option Explicit in the VB help, and early and late binding to objects if you are really keen. The line Dim frm as Form at the beginning of the procedure would be good practice.

    Hope this helps

  12. #12
    Join Date
    Feb 2004
    Location
    UK
    Posts
    246
    Hi, we meet again

    Thanks for the pointer, hopefully you'll bear with me as I know nothing about VB.
    I've changed the frm.Tag = line to Me.Name

    Private Sub Find_Policies_Click()
    On Error GoTo Err_Find_Policies_Click

    Dim stDocName As String
    Dim frm As Form_Policies_frm

    stDocName = "Int_search_mco2"
    DoCmd.RunMacro stDocName

    Set frm = [Forms]!Policies_frm
    frm.Tag = Me.Name

    Set frm = Nothing


    Exit_Find_Policies_Click:
    Exit Sub

    Err_Find_Policies_Click:
    MsgBox Err.Description
    Resume Exit_Find_Policies_Click

    End Sub

    Explicit I take means that you declare a object so that Access can be in no doubt what you are referring to?
    So what I have done is put in a line just after "Dim stDocName As String" of
    "Dim frm As Form_Select_records". Now I get the folloing error messages
    "The expression you entered referes to an object that is closed or doesn't exist" This is when the form opens
    But on trying to exit the form I get the same message as before
    "The action or method requires a Form Name argument"

    Not certain if the 1st error message has anything to do with this, but I obviously need to understand what each part of the code is doing. In the calling forms the lines that are applicable are?

    Set frm = [Forms]!Policies_frm
    frm.Tag = Me.Name
    Set frm = Nothing

    In the opening form the applicable code is?

    DoCmd.OpenForm Me.Tag, acNormal

  13. #13
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Hi

    Precisely on the Option Explicit - it just prevents the easiest and most common error in your code - typing errors

    The code should be:

    Private Sub Find_Policies_Click()
    On Error GoTo Err_Find_Policies_Click

    Dim stDocName As String
    'Dim frm As Form_Policies_frm
    'You declare frm as a Form object with dim frm as ....; you assign it to a specific form when you use Set frm = ...
    Dim frm As Form

    stDocName = "Int_search_mco2"
    DoCmd.RunMacro stDocName

    Set frm = [Forms]!Policies_frm
    frm.Tag = Me.Name

    Set frm = Nothing

    Exit_Find_Policies_Click:
    Exit Sub

    Err_Find_Policies_Click:
    MsgBox Err.Description
    Resume Exit_Find_Policies_Click

    End Sub

    However, your policies_frm form needs to be open either in design or normal view before you can assign a value to the tag property. I presume this is what your macro does? If it isn't open you'll get a message box telling you that the database can't find the form. Hope this is getting you closer...

  14. #14
    Join Date
    Apr 2004
    Location
    Kingsland, Georgia
    Posts
    231

    goodness...

    Disclaimer: I am not a VB expert. Anyone feel free to correct me as long as you know what you're talking about better than I do. I've had enough chiding by uninformed and partially ignorant parties here at work today ...

    Not certain if the 1st error message has anything to do with this, but I obviously need to understand what each part of the code is doing. In the calling forms the lines that are applicable are?

    Set frm = [Forms]!Policies_frm
    frm.Tag = Me.Name
    Set frm = Nothing
    At the top of your Sub, you need to declare frm as a Form object, not a Form_Policies_frm. What you are doing is declaring a variable that is of the Form type. That is so you can set it to another one and edit it as a form. Kinda like declaring
    Code:
    Dim mam As Mammal
    (I know this is a goofy example). so you have an generic mammal, with the general mammal characteristics (warm blooded, vertebrates, etc...). set mam = Cat. would tell you which mammal you're referencing. Then you could reference the cat's properties (hair color, gender, weight) by mam. mam.gender=Male. so you could jump from mammal to mammal by switching the particular animal the mam was set to. so you could:
    Code:
    set mam=Dog
    mam.Weight=40
    set mam=Whale
    mam.Weight=40000
    you're changing mam each time, but it's referencing a different object.
    so in your code, you'll
    Code:
    Dim frm as Form
    instead of as Form_Policies_frm. That's like saying
    Code:
    Dim mam as BigOne_Twelve
    . What's a BigOne_Twelve? exactly. That's what VB is thinking when you Dim frm as Form_policies_frm. You'd have to create a class called Form_Policies_frm to declare frm as that type of object. anyways, that's mor than you wnted to know (and probably wrong ).

    Back to your question...when you say
    Code:
    Set frm = [Forms]!Policies_frm
    , you're setting your variable frm to reference the object (a Form in this case)Policies_frm (the name of your form) in the collection of Forms in your project.
    Code:
    frm.Tag=Me.Name
    sets the .Tag property of the Policies_frm form (since that's what frm now represents) to the .Name of the current form (referenced by the Me keyword).
    Code:
    Set frm=Nothing
    releases the resources you're tying up in memory by having frm point to that particular form (Policies_frm).


    Now,
    Code:
    DoCmd.OpenForm Me.Tag, acNormal
    says to open a form, and that the name of the form to be opened is stored in the .Tag property of the current form (again referenced by the Me keyword).
    acNormal tells it to open in normal mode, versus design mode or whatever.

    your course of progress from beginning to end when a user clicks the button should be to
    1)open the proper form (usually in the .Tag property of the current form, except maybe from the first form)
    2)write the name of the current form into the .Tag property of that form.
    3)close or hide the current form.


    hope this helps some. i'm not the best at coming up with examples, but if you need anything else, post it. later

Posting Permissions

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