Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Star Lounger
    Join Date
    Jan 2001
    Location
    Bethel, CT, USA
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Open Form & SubForm

    In Access 97,I have database with a Main form which includes a subform generated from a query. The setup is similar to the Northwind Orders Db, with a Details table to hold linking info.
    I want to place a button on another form to open my Main form to a specific record. The button wizard guided me through all the steps and I thought I was done. But, when I click the button, I receive 2 consecutive requests to enter parameter values. The first one wants KeyField.MainForm, the second Keyfield.Details. I have no idea how to alter the VBA code to accomplish this behind the scenes, or even what parameters I'm supposed to enter. Is there a simple way to fix this? I don't care if the form opens filtered to the single record or opens all records with the focus on the correct one.

  2. #2
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Pennsylvania, USA
    Posts
    144
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Open Form & SubForm

    I believe that I just finished a task that you are trying.

    Are you using a Command Button, on a main form such as a main switch board, or is it on another form. The problem may be that you need to create a macro to open your main form.

    Give me some more details.
    threecrow

    Don't make excuses. It's what you do, not why you didn't.

  3. #3
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Pennsylvania, USA
    Posts
    144
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Open Form & SubForm

    Please disregard previous post. Was answering a question that you did not ask. The little hampster took a nap on the wheel.

    Access is asking for parameters that you did not put in your query. Post some more details I will try to get it corrected.
    threecrow

    Don't make excuses. It's what you do, not why you didn't.

  4. #4
    Star Lounger
    Join Date
    Jan 2001
    Location
    Bethel, CT, USA
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Open Form & SubForm

    Hi John,
    The parameter values its requesting are definitely not part of the query, I believe are they are the Child and Master links between the Main form and SubForm. Also, a button to simply OpenForm works fine. Its just opening to a specific record that's a problem and the Wizard wrote the code.
    Is there a way to tell the OpenForm what these parameters are in the arguments? And why do I need to tell it?
    P.S. Using a Macro does the same thing.

  5. #5
    Star Lounger
    Join Date
    Jan 2001
    Location
    Bethel, CT, USA
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Open Form & SubForm

    One more thing. If I just click the requestors away "OK", "OK", then the form opens to the correct record and with the subform data intact. This should be a clue to something but I can't figure out what.

  6. #6
    New Lounger
    Join Date
    Jan 2001
    Location
    Victoria, BC
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Open Form & SubForm

    You may have done this. Select the subForm and the it's properties. Under the Data tab fill in Link Child/Master Fields. I am using a textbox, which when filled in, populates the subForm.

  7. #7
    Star Lounger
    Join Date
    Jan 2001
    Location
    Bethel, CT, USA
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Open Form & SubForm

    Good try, but that's not it. Everything seems to be set properly and the form opens normally fully populated with subform data as it should.
    When I go into the Northwinds sample database and add a button to do the same thing as in mine, it works fine.
    I know I'm missing some simple little thing, as you suggest, but in comparing my Db with the sample and in checking for errors I'm not finding it. [img]/w3timages/icons/dizzy.gif[/img]

  8. #8
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Open Form & SubForm

    Well, unless your form, table, field and query names are exactly the same as the Northwinds sample, you aren't doing exactly the same thing. So let's start with a few questions:

    1. Is the form already open--i.e., you're trying to change the current record from another form or the main form is hidden and you want to unhide it and change the record?

    2. Post the code behind the command button so we can see what's wrong with it. There are several ways to do what you're trying to do, but we need to know which way you chose in order to suggest corrections.

    3. Is your KeyField field actually on the form, or is it only in the form's recordset?

    4. If the Keyfield is actually bound to a control on the form, what is the name of the control. You can confuse Access thoroughly by naming your control and your field the same thing.
    Charlotte

  9. #9
    Star Lounger
    Join Date
    Jan 2001
    Location
    Bethel, CT, USA
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Open Form & SubForm

    Hi Charlotte,
    1. The form I'm trying to open is closed.
    2. Here is the code that the button wizard wrote:

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "ECN Form"
    stLinkCriteria = "[IDNumber]=" & Me![IDNumber]

    DoCmd.OpenForm stDocName, , , stLinkCriteria


    3. The fields for both forms are the same and on the form. The one I want to open has it as a key field. The one I'm opening it from, does not.
    4. I'm not clear on this question. The name of the Form field is [IDNumber] the name of the Table field is [IDNumber]. This was done by the Access form wizard. Aren't a control and a form field the same thing?

  10. #10
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Open Form & SubForm

    On question 4, you have to realize that the wizard is stupid and is still writing Access 95 code, so don't expect too much from it. No, the fields and the controls ase NOT the same, although Microsoft seems to ignore that fact to avoid "forcing" naming conventions on developers! You need to change the control names to things like txtIDNumber when it's a textbox bound to the IDNumber field, in order to avoid confusing Access. Otherwise, calculated controls may wind up displaying #ERROR messages instead of values. In your case, make it ...

    stLinkCriteria = "[IDNumber]=" & Me![txtIDNumber]

    and see if that makes a difference.
    Charlotte

  11. #11
    Star Lounger
    Join Date
    Jan 2001
    Location
    Bethel, CT, USA
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Open Form & SubForm

    I assume you mean that a text box on a table is a field and a text box on a form is a control? Do I have the terminology correct now?
    Changing the name does not help. Even replacing the name with an actual specific record value does not change the response.
    i.e. stLinkCriteria = "[IDNumber]=3"
    I still can't help thinking that it has something to do with the way the Main form and subform are linked because (as stated in the first post) it is asking for parameter values for the link (fields or controls) for the two (forms or tables).
    But what do I know?
    The Main form was originally wizard generated. Then I looked at Northwind to see how to do the subform thing. I probably missed something. Although everything seems to work fine except for this.

  12. #12
    4 Star Lounger
    Join Date
    Dec 2000
    Location
    London, Ontario, Canada
    Posts
    437
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Open Form & SubForm

    <hr>The first one wants KeyField.MainForm, the second Keyfield.Details. <hr>
    This sounds very much like an incorrect Child/Master parameter error. In the subform properties are the child and master set to <font color=008080>KeyField</font color=008080> and if so, is there a field on the main and subform named <font color=008080>KeyField</font color=008080>? Sorry if this sounds simplistic but sometimes simple answers are the best.

  13. #13
    Star Lounger
    Join Date
    Jan 2001
    Location
    Bethel, CT, USA
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Open Form & SubForm

    Oh boy! What's the matter with Me!?
    O.K. guys, sorry to make you all twist your brains for a neophyte like myself. Here's what was happening. There was a procedure behind the form control [IDNumber]. That number was referenced by another control to concatenate letter characters onto it for another purpose. Both of these procedures were copied from other forms that have been in use for a couple of years. No problem, until I use them in a new form to which I add a subform. Now with the subform linked to the values entered to the table from those controls, when I try to do an OpenForn with LinkCriteria, Access gets confused.
    Why? Because all the controls, fields and criteria values had the same name!
    Simply adding Me! to the controls' procedures alleviated the confusion. I have since gone through and renamed or qualified every identifier in the new database.
    So, what's wrong with Me!?
    Nothing now, except possibly incurring the wrath of everyone whom I've frustrated in their attempts to help someone who thinks they've checked everything.
    Yep, its always the simple stuff that'll get you in the end.
    Thank you everyone for all your thoughtful assistance.

  14. #14
    4 Star Lounger
    Join Date
    Dec 2000
    Location
    London, Ontario, Canada
    Posts
    437
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Open Form & SubForm

    <hr>Yep, its always the simple stuff that'll get you in the end.
    <hr>
    Isn't that the truth. Great to hear you got it solved. [img]/w3timages/icons/smile.gif[/img]

  15. #15
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Pennsylvania, USA
    Posts
    144
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Open Form & SubForm

    Simple is as simple does.
    threecrow

    Don&#39;t make excuses. It&#39;s what you do, not why you didn&#39;t.

Page 1 of 2 12 LastLast

Posting Permissions

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