Results 1 to 4 of 4
  1. #1
    3 Star Lounger
    Join Date
    Oct 2001
    Location
    Newport, Gwent, Wales
    Posts
    257
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Data from FormA to FormB, or just open FormB (Win 2k Access 2k)

    Dear All

    I've got a problem with a data entry form, let's call it FormB. FormB is opened in one of two ways, either by the not in list action from one of three other forms, or directly from a button on a 'menu' form.

    Now when FormB opens from any of the three forms I put data into it (using a module called isloaded and OpenArgs that HansV helped me with), this works great, and it's stopped my users from spelling things differently in FormB to the entry that set off the not in list event on FormA (any one of the three forms that could be FormA).

    My problem starts when the user wants to simply use the form without triggering the not in list event (FormB is used to enter a contact's name and details, so if a new contact is made they can be entered in advance). When the user calls FormB from the button the code, quite rightly, errors out and wants to know what my OpenArgs variable should be, "invalid use of null" is the precise message. I've tried to put the point at which the variable is set inside the if ....... then statement, still no luck. I'm using the OpenArgs option to transfer NewData from a combo box on FormA (the not in list event) to a text box on FormB, this works fine, how do I just open the form?

    At the moment I'm using a duplicate form without the on open action, it just doesn't seem to be as neat a solution as it could be.

    Here's a sample of the code, guess the problem is staring me in the face, but I'm not seeing it.

    Private Sub Form_Open(Cancel As Integer)
    On Error GoTo err_form_open

    Dim parameter1 As String

    DoCmd.RunCommand acCmdRecordsGoToNew
    If isloaded("FormA") Then
    Me.custname = AControlOnFormA
    Else
    If isloaded("FormA2") Then
    parameter1 = Me.OpenArgs
    Me.custname = parameter1
    Else
    DoCmd.RunCommand acCmdRecordsGoToNew
    End If
    End If
    exit_form_open:
    Exit Sub

    err_form_open:
    MsgBox Err.Description
    Resume exit_form_open

    End Sub

    Thanks for the help

    Ian

  2. #2
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: Data from FormA to FormB, or just open FormB (Win 2k Access 2k)

    >>how do I just open the form<<
    DoCmd.OpenForm "your form name"

    If the OpenArgs can be null, you should either set the variable Parameter1 as a variant or test the OpenArgs is null.

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Data from FormA to FormB, or just open FormB (Win 2k Access 2k)

    You could start by checking if OpenArgs is empty:

    If IsNull(Me.OpenArgs) Then
    ' actions to perform if OpenArgs is empty
    ...
    Else
    ' actions to perform if OpenArgs is not empty
    Me.custname = Me.OpenArgs
    End If

    Note: you call DoCmd.RunCommand acCmdRecordsGoToNew twice, you only need the first one.

  4. #4
    3 Star Lounger
    Join Date
    Oct 2001
    Location
    Newport, Gwent, Wales
    Posts
    257
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Data from FormA to FormB, or just open FormB (Win 2k Access 2k)

    patt

    Tried the parameter1 As Variant, it appears to work, in both scenarios. <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>

    Thanks

    Hans

    Thanks for the suggestion.

    Ian

Posting Permissions

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