Results 1 to 12 of 12
  1. #1
    shylock is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Sep 2018
    Location
    Dayton, Ohio
    Posts
    100

    DpCmd.OpenForm

    I have two forms, say frm1 and frm2. In a control on frm1, in the on click event, I have the following:



    DoCmd.OpenForm "frmAddServicestoDT", , , , , , Me.cboServerNm

    In frm2, in the Form_Load sub, I have the following:

    Dim strServerName As String

    strServerName = Me.OpenArgs

    If Len(strServerName) > 0 Then
    Me.txtSName.Value = strServerName
    Else
    myMsg = MsgBox("You must supply a server name!", vbInformation, "Invalid Server Name")
    Cancel = True
    DoCmd.GoToControl "txtSName"
    End If

    In debugging, I confirm that me.cboServerNm has a legitimate string. However, the strServerName = me.OpenArgs expression give a Run-time error '94': Invalid use of Null. I have tried using the On Open event instead of On Load for frm2, but get the same error. Does anyone know what I am doing wrong?

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    When you confirm, are you using a breakpoint or message box in code or visually looking at the combo? It's possible the combo's bound column is Null even if you see a value. Try one of the above to see what value it contains in the OpenForm line.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Oh, and I deleted your duplicate thread. There's no need to post the same question twice.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    shylock is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Sep 2018
    Location
    Dayton, Ohio
    Posts
    100
    Quote Originally Posted by pbaldy View Post
    Oh, and I deleted your duplicate thread. There's no need to post the same question twice.
    Thank myou for deleting the duplicate post. I set break points in debugging and was able to confirm the combo had a server name in it.

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Can you attach the db here? I've used OpenArgs many times, and never had this problem of it dropping the value.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    shylock is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Sep 2018
    Location
    Dayton, Ohio
    Posts
    100
    Quote Originally Posted by pbaldy View Post
    Can you attach the db here? I've used OpenArgs many times, and never had this problem of it dropping the value.
    Sorry, I am not pemitted to attach the DB. I would be canned fom the job.

    I my code correct on the receiving end? Specifically, the me.OpenArgs portion of strServerName = me.OpenAgrgs?

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    It doesn't account for a Null value being passed, but otherwise okay. I think the real question is why the value is Null. You can get around the error several ways, here's one:

    strServerName = Nz(Me.OpenArgs, "")
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    And by the way I'd handle the selection of a server in the first form, not the second.

    Code:
    If Len(Me.cboServerNm & vbNullString) > 0 Then
      DoCmd.OpenForm...
    Else
      MsgBox "Must select server"
    End If
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    shylock is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Sep 2018
    Location
    Dayton, Ohio
    Posts
    100
    Thanks, Paul. I do select the server name in frm1. It is the server name that I am passing to the second form which use it to look up the services contained on that server.

  10. #10
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You test in frm2 whether a selection has been made (or at least that one was received). I'm saying I would do that test in the first form, not the second.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  11. #11
    shylock is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Sep 2018
    Location
    Dayton, Ohio
    Posts
    100
    Paul:

    I solved the problem. I was so tired that I wasn't thinking straight. I finally remembered that a combo box can have more than one column. I simply had to pass the correct column into the second form as below:

    If Len(Me.cboServerNm & vbNullString) > 0 Then
    DoCmd.OpenForm "frmAddServicestoDT", , , , , , OpenArgs:=Me.cboServerNm.Column(1, Me.cboServerNm)
    Else
    MsgBox ("Please re-enter the server name.")
    End If

    Thanks for your efforts.

  12. #12
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    No problem.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Do.Cmd.OpenForm with Where clause
    By moneypennie21 in forum Access
    Replies: 5
    Last Post: 05-24-2017, 05:08 AM
  2. Openform with two criteria
    By prendergi in forum Forms
    Replies: 3
    Last Post: 05-20-2016, 03:32 PM
  3. OpenForm to specific tab
    By rivereridanus in forum Access
    Replies: 1
    Last Post: 06-28-2012, 07:32 PM
  4. What actually happens at docmd.openform
    By Beorn in forum Programming
    Replies: 4
    Last Post: 01-05-2011, 02:19 PM
  5. Getting to a tab on openform
    By Swarland in forum Programming
    Replies: 5
    Last Post: 12-12-2010, 11:22 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums