Results 1 to 7 of 7

Thread: Form_open event

  1. #1
    Join Date
    Aug 2003
    Posts
    123

    Question Unanswered: Form_open event

    I'm trying to open a form from another form, and pass a value as an argument in the Form_Open event. However, it keeps giving the runtime 2501 "The OpenForm action was canceled". Here is the code...

    Private Sub cmdEdit_Click()
    DoCmd.OpenForm "frmSecurityEdit", acNormal, , , , , txtCurrRow
    End Sub


    The open event has:
    Private Sub Form_Open(varTicker, Cancel As Integer)

    txtCurrRow is a text box that holds the value being passed into varTicker.

  2. #2
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    You can try doing it this way...

    Docmd.openform "frmSecurityEdit"
    Forms!frmSecurityEdit!varTicker = me!txtCurrRow

    assuming you have a textbox field on the current form called txtCurrRow and a textbox field on the frmSecurityEdit called varTicker.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  3. #3
    Join Date
    Aug 2003
    Posts
    123
    The basic concept is that I'm going from a summary window to a detail window. So I'll have a list of items, click on one and click a "Detail" command button. The button opens the next window, with that window looking up the rest of the columns for a single record.

    So when the new form opens, it also needs to query a table using the passed argument as a parameter.

  4. #4
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    You can also do something like...

    Docmd.openform "frmSecurityEdit"
    Forms!frmSecurityEdit!varTicker = me!txtCurrRow
    Forms!frmSecurityEdit!MyFieldToRequery.requery
    Forms!frmSecurityEdit!MyListBoxField.requery
    etc...etc...

    If you have a listbox or query based on a parameter of varTicker and varTicker is a textbox field on the form frmSecurityEdit, then you only need to issue a requery command to that query/listbox, etc. on the form. (if varTicker isn't a textbox field on the form, why not make it one?) Then just set the parameter of your query =Forms!frmSecurityEdit!varTicker.

    I guess I don't understand why you're trying to pass a value into varTicker as a parameter when you can make it a textbox field on the form and set your query criteria to = the textbox value.

    If the form's recordsource is a query, just set it to =Forms!frmSecurityEdit!varTicker (the textbox field). Once you open the form...
    Docmd.openform "frmSecurityEdit"
    Forms!frmSecurityEdit.requery

    or even better, just set the form's recordsource criteria to equal the calling form's textbox (i.e. I think you call it txtCurrRow). So in the criteria of the RecordSource query for the form frmSecurityEdit would =Forms!MyMainForm!txtCurrRow. Then you don't have to worry about passing anything.
    Last edited by pkstormy; 06-19-07 at 17:48.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  5. #5
    Join Date
    Aug 2003
    Posts
    123
    I guess I don't need to pass the argument; it was just the initial way I thought of getting the form to load the data as soon as it opened. Thanks.

  6. #6
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    No problem. Hope it works out ok for you. If not, just post the issue.
    Last edited by pkstormy; 06-19-07 at 18:42.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  7. #7
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    I don't really think you can change the Sub Form_Open by adding parameters that Access didn't intend. The txtCurrRow you added is called OpenArgs, and can be retrieved in the opening form's Form_Open or Form_Load sub and assigned to whatever you'd like to assign it to, with something like this:

    Code:
    If Len(Nz(Me.OpenArgs, "")) > 0 Then
        varTicker = Me.OpenArgs
    End If
    varTicker will then be assigned the value that txtCurrRow held when passed.
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

Posting Permissions

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