Log in

View Full Version : OpenArgs Statement



Will_J
10-03-2013, 10:15 AM
Hi Guys & Girls,

Thanks in advance for your help.

I presently have this problem. I have a reminders form that Opens from a variety of different forms, for arguments sake let's say Production and Meeting both have a button with an OnClick events then leads to the following line of code;


DoCmd.OpenForm "frmEmail", , , , acFormAdd, , Me.[ProductionID]

DoCmd.OpenForm "frmEmail", , , , acFormAdd, , Me.[MeetingID]

The problem occurs when I have the

Private Sub Form_Load()
If Not IsNull(Me.OpenArgs) Then
DoCmd.GoToRecord , , acNewRec
Me.[ProductionID] = Me.OpenArgs
End If
End Sub

I want the OpenArgs to be variable to allow for the correct ID to be dropped in the relevant combo box. I have tried;


Private Sub Form_Load()
If Not IsNull(Me.OpenArgs) Then
DoCmd.GoToRecord , , acNewRec
Me.[ProductionID] = Me.OpenArgs
Me.[MeetingID] = Me.OpenArgs
End If
End Sub

Addmitedlty, the logic dosen't work forme I would have to write another statement however I've spent to long dumbfounded and was hoping you guys & girls could give me a little help.

Many Thanks,

Will

HiTechCoach
10-04-2013, 09:08 AM
One way to handle this is to pass more information in the OpenArgs.

Example:


DoCmd.OpenForm "frmEmail", , , , acFormAdd, , "ProductionID," & Me.[ProductionID]

and



DoCmd.OpenForm "frmEmail", , , , acFormAdd, , "MeetingID," & Me.[MeetingID]


Then use this:



Private Sub Form_Load()

Dim strControlName as String
Dim lngID as Long

If Not IsNull(Me.OpenArgs) Then
' retrieve the control name from the OpenArgs
strControlName = Left(Me.OpenArgs, Instr(Me.OpenArgs(), ",") -1)

' Retrieve the ID from OpenArgs
lngID = Mid(Me.OpenArgs,Instr(Me.OpenArgs(), ",")+1)

'Go to a new record
DoCmd.GoToRecord , , acNewRec

' set the control with the ID
Me(strControlName = lngID
End If
End Sub