Dang. Let me redo that pasting job.
In a standard module, try:
'======================================
' This function extracts the string value at an ordinal position
' from the form's OpenArgs Property. The string values are
' expected to be delimited by a comma. nth is the ordinal
' value in the OpenArgs string to retrieve the substring from.
' No string will be passed back from this function when there
' is no OpenArgs Property and when nth exceeds the number
' of substrings in the OpenArgs Property.
'======================================
Public Function getOpenArg(sOpenArgs As String, nth As Long) As String
On Error GoTo ErrHandler
Dim pos As Long
Dim idx As Long
Dim nStart As Long
nStart = 1
For idx = 1 To nth
pos = InStr(nStart, sOpenArgs, ",", vbDatabaseCompare)
If (idx = nth) Then
If (pos = 0) Then
getOpenArg = Mid$(sOpenArgs, nStart, _
Len(sOpenArgs) - nStart + 1)
Exit For
ElseIf (pos > 0) Then
getOpenArg = Mid$(sOpenArgs, nStart, pos - nStart)
Exit For
End If
ElseIf (pos = 0) Then
Exit For ' Ordinal # exceeds # of OpenArgs.
End If
nStart = pos + 1
pos = 0
Next idx
Exit Function
ErrHandler:
MsgBox "Error in getOpenArg( )." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & vbCrLf & Err.Description
Err.Clear
getOpenArg = ""
End Function ' getOpenArg( )
In the form's module, try:
Private Sub Form_Open(Cancel As Integer)
On Error GoTo ErrHandler
Dim sSomeVal As String
If (Len(Me.OpenArgs) > 0) Then
sSomeVal = getOpenArg(Me.OpenArgs, 2)
MsgBox "*" & sSomeVal & "*"
End If
Exit Sub
ErrHandler:
MsgBox "Error in Form_Open( ) in" & vbCrLf & _
Me.Name & " form." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & vbCrLf & Err.Description
Err.Clear
End Sub
HTH.
Gunny
See
http://www.QBuilt.com for all your database needs.
See
http://www.Access.QBuilt.com for Microsoft Access tips.
(Please remove ZERO_SPAM from my reply E-mail address so that a message will
be forwarded to me.)
- - -
If my answer has helped you, please sign in and answer yes to the question
"Did this post answer your question?" at the bottom of the message, which
adds your question and the answers to the database of answers. Remember that
questions answered the quickest are often from those who have a history of
rewarding the contributors who have taken the time to answer questions
correctly.