• containers,collections,objects

    Author
    Topic
    #1768541

    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.

    Viewing 2 reply threads
    Author
    Replies
    • #1779877

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

    • #1779891

      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.

      • #1779953

        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?

    • #1779962

      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.

      • #1780085

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

        • #1780131

          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.

    Viewing 2 reply threads
    Reply To: containers,collections,objects

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: