Results 1 to 7 of 7
  1. #1
    aross
    Guest

    containers,collections,objects

    Using Access97 SR2
    I want to set the 'Source' property of an existing form to an arbitrary value before opening it. Somehow I've convinced
    myself that some invocation involving containers / collections/object(s) can do this. Has anyone out there solved this or a similar problem? Whatever documentation I've looked at has me boggled.

  2. #2
    Lounger
    Join Date
    Feb 2001
    Location
    TX, USA
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: containers,collections,objects

    What do you mean by 'set the 'Source' property of an existing form to an arbitrary value'? Are you referring to the RECORDSOURCE?

  3. #3
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    The Netherlands
    Posts
    216
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: containers,collections,objects

    You can set the RecordSource property using VBA.

    First load your form hidden.
    Then set the recordsource with forms![frmMyForm].RecordSource = "MySQLStatement"
    Then Refresh the form
    And finaly make the form visible.

  4. #4
    aross
    Guest

    Re: containers,collections,objects

    Many thanks ... however when I run the following

    grab1: who = Mid$(mycursor, 41, 6)
    sqlTxt = "SELECT dumpmast.*, * FROM dumpmast " _
    & "WHERE dumpmast.empNum = " & who & ";"
    DoCmd.OpenForm "nachamatcher", acDesign
    Forms!nachamatcher.RecordSource = sqlTxt
    DoCmd.Close acForm, "nachamatcher", acSaveYes ''' grab1 works to here
    DoCmd.OpenForm "nachamatcher", acNormal ****
    Set frm = Forms!nachamatcher

    the starred line produces Runtime error 2501

    " the OpenForm action was cancelled

    You used a method of the DoCmd object to carry out an action in VB but then clicked Cancel in a dialog box.

    For example, you used the Close method to close a changed form, then clicked Cancel in the dialog box which asked if you want to save it. "

    What have I done wrong?

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

    Re: containers,collections,objects

    Just trap the error and ignore it. This is one of those annoying event-related messages that usually doesn't mean anything except that you didn't do things in the order Access expected.
    Charlotte

  6. #6
    aross
    Guest

    Re: containers,collections,objects

    Yes, I can trap the error but how do I (re-)open the form?

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

    Re: containers,collections,objects

    Sorry, I must have missed something. Why are you closing it in the first place? You needn't open the form in design view to set its recordsource, you can do that at runtime. And you don't need to save anything if you're going to run this whenever you open the form. If you want to save a specific recordsource, the simplest way is to do it in the design view and skip the code part.
    Charlotte

Posting Permissions

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