Trying to populate form control with OpenArgs

Hargo

Registered User.
Local time
Today, 11:32
Joined
Sep 4, 2014
Messages
19
Hi everyone, Newbie alert!!!

Can anyone suggest what is wrong with my code please?


I have this code in a button on my Patient Form:

Code:
DoCmd.OpenForm "frm_Admissions", acNormal, , , acFormAdd, , "NHS Number|" & Me.[NHS Number]


And this in my Admissions form LoadEvent:

Code:
Private Sub Form_Load()
  'Use this version if the ID is a number
  Dim x As Variant
  Dim strControl As String
  Dim lngID As Long

  'If parameters exist, use them
  If Len(Me.OpenArgs) > 0 Then
    'Split creates a zero-based array from the input string
    x = Split(Me.OpenArgs, "|")
    strControl = x(0)
    lngID = x(1)

    Me(strControl) = lngID
  End If
End Sub

RESULT = Run-time error '2467'

The expression you entered refers to an object that is closed or doesn't exist



Borrowed code from: http://www.datawright.com.au/access_resources/access_docmd.openform_arguments.htm
 
Which line does the error occur? What is strControl? What is this line Me(strControl) supposed to do?
 
The error is in the DoCmd line - I'm assuming there's a syntax error in the openargs part at the end

The rest I lifted from the source in my hyperlink so I haven't a clue, sorry


It claimed to be code for passing a value (in this case NHS Number)
 
Please can you show more code just before you the line where you are trying to open the second form?
 
Thanks pr2-eugin

I've solved it....I had a form close command before my line of code!!!!! Doh :banghead:
 
That is what I thought. Well kudos for figuring it on your own. :) Good luck !
 

Users who are viewing this thread

Back
Top Bottom