Is this the proper way of splitting the string

S

Steve

Dim x As Integer

x = InStr(Me.OpenArgs, Me.[Entity Name])

If Me.NewRecord Then
Me.[Entity Name] = Left(Me.OpenArgs, x)
Me.[Entity Type] = Right(Me.OpenArgs, Len(Me.OpenArgs - x))
End If

This function will lock the strings inputed by another form. Well I
need 2 fields locked with the data, and the only way to do that is by
splitting it. This keeps giving me the error "Invalid use of Null".

Am I doing something wrong?
 
D

Douglas J. Steele

If you haven't populated it yet, then Me.[Entity Name] is going to be null.

What exactly are you passing as the OpenArgs parameter of the OpenForm
method? What are you hoping the InStr function will find?
 
S

Steve

The OpenArgs is passing 2 strings attached, the testing name I've given
it is "Testing Name EntityHTML Document" (without out the quotes). I'm
hoping the InStr will find the 1st field name "Testing Name Entity" and
allow me to split the string.

If you haven't populated it yet, then Me.[Entity Name] is going to be null.

What exactly are you passing as the OpenArgs parameter of the OpenForm
method? What are you hoping the InStr function will find?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Steve said:
Dim x As Integer

x = InStr(Me.OpenArgs, Me.[Entity Name])

If Me.NewRecord Then
Me.[Entity Name] = Left(Me.OpenArgs, x)
Me.[Entity Type] = Right(Me.OpenArgs, Len(Me.OpenArgs - x))
End If

This function will lock the strings inputed by another form. Well I
need 2 fields locked with the data, and the only way to do that is by
splitting it. This keeps giving me the error "Invalid use of Null".

Am I doing something wrong?
 
S

Steve

Well, I changed it up enough, here's the code I have now:

Dim x As Integer

x = InStr(Me.OpenArgs, "|")

If Me.NewRecord Then
Me.[Entity Name] = Left(Me.OpenArgs, x)
Me.[Entity Type] = Right(Me.OpenArgs, Len(Me.OpenArgs - x))
End If

In the OpenForm button I have on the primary form, I put the | to
seperate the two to see if it would help me split the string. I get
this error: "Type mismatch" and it highlights: Me.[Entity Type] =
Right(Me.OpenArgs, Len(Me.OpenArgs - x)).

Hope this helps also.
If you haven't populated it yet, then Me.[Entity Name] is going to be null.

What exactly are you passing as the OpenArgs parameter of the OpenForm
method? What are you hoping the InStr function will find?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Steve said:
Dim x As Integer

x = InStr(Me.OpenArgs, Me.[Entity Name])

If Me.NewRecord Then
Me.[Entity Name] = Left(Me.OpenArgs, x)
Me.[Entity Type] = Right(Me.OpenArgs, Len(Me.OpenArgs - x))
End If

This function will lock the strings inputed by another form. Well I
need 2 fields locked with the data, and the only way to do that is by
splitting it. This keeps giving me the error "Invalid use of Null".

Am I doing something wrong?
 
D

Douglas J. Steele

Does Me.[Entity Name] contain anything?

My advice would be to put a special character as a delimiter, a character
that will never appear in the data that's being passed (such as ~), so that
you'll have "Testing Name Entity~HTML Document"

Then, use:

Dim x As Integer

x = InStr(Me.OpenArgs, "~")

If x > 0 Then
If Me.NewRecord Then
Me.[Entity Name] = Left(Me.OpenArgs, x - 1)
Me.[Entity Type] = Mid(Me.OpenArgs, x + 1)
End If
End If

Alternatively, assuming you're using Access 2000 or newer, you could use

Dim x As Integer
Dim varArgs As Variant

x = InStr(Me.OpenArgs, "~")

If x > 0 Then
If Me.NewRecord Then
varArgs = Split(Me.OpenArgs, "~")
Me.[Entity Name] = varArgs(0)
Me.[Entity Type] = varArgs(1)
End If
End If


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Steve said:
The OpenArgs is passing 2 strings attached, the testing name I've given
it is "Testing Name EntityHTML Document" (without out the quotes). I'm
hoping the InStr will find the 1st field name "Testing Name Entity" and
allow me to split the string.

If you haven't populated it yet, then Me.[Entity Name] is going to be null.

What exactly are you passing as the OpenArgs parameter of the OpenForm
method? What are you hoping the InStr function will find?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Steve said:
Dim x As Integer

x = InStr(Me.OpenArgs, Me.[Entity Name])

If Me.NewRecord Then
Me.[Entity Name] = Left(Me.OpenArgs, x)
Me.[Entity Type] = Right(Me.OpenArgs, Len(Me.OpenArgs - x))
End If

This function will lock the strings inputed by another form. Well I
need 2 fields locked with the data, and the only way to do that is by
splitting it. This keeps giving me the error "Invalid use of Null".

Am I doing something wrong?
 
S

Steve

Yeah! That worked! Thanks man.
Does Me.[Entity Name] contain anything?

My advice would be to put a special character as a delimiter, a character
that will never appear in the data that's being passed (such as ~), so that
you'll have "Testing Name Entity~HTML Document"

Then, use:

Dim x As Integer

x = InStr(Me.OpenArgs, "~")

If x > 0 Then
If Me.NewRecord Then
Me.[Entity Name] = Left(Me.OpenArgs, x - 1)
Me.[Entity Type] = Mid(Me.OpenArgs, x + 1)
End If
End If

Alternatively, assuming you're using Access 2000 or newer, you could use

Dim x As Integer
Dim varArgs As Variant

x = InStr(Me.OpenArgs, "~")

If x > 0 Then
If Me.NewRecord Then
varArgs = Split(Me.OpenArgs, "~")
Me.[Entity Name] = varArgs(0)
Me.[Entity Type] = varArgs(1)
End If
End If


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Steve said:
The OpenArgs is passing 2 strings attached, the testing name I've given
it is "Testing Name EntityHTML Document" (without out the quotes). I'm
hoping the InStr will find the 1st field name "Testing Name Entity" and
allow me to split the string.

If you haven't populated it yet, then Me.[Entity Name] is going to be null.

What exactly are you passing as the OpenArgs parameter of the OpenForm
method? What are you hoping the InStr function will find?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Dim x As Integer

x = InStr(Me.OpenArgs, Me.[Entity Name])

If Me.NewRecord Then
Me.[Entity Name] = Left(Me.OpenArgs, x)
Me.[Entity Type] = Right(Me.OpenArgs, Len(Me.OpenArgs - x))
End If

This function will lock the strings inputed by another form. Well I
need 2 fields locked with the data, and the only way to do that is by
splitting it. This keeps giving me the error "Invalid use of Null".

Am I doing something wrong?
 
E

e.mel

you can also use the split() function. It takes the string, and a
seperator character and spits out an array:

'assume OpenArgs = "One|Two|5ive"

Dim args() As String
args = Split(OpenArgs, "|")

'then
'args(0) = "One"
'args(2) = "Two"
'args(3) = "5ive"



Well, I changed it up enough, here's the code I have now:

Dim x As Integer

x = InStr(Me.OpenArgs, "|")

If Me.NewRecord Then
Me.[Entity Name] = Left(Me.OpenArgs, x)
Me.[Entity Type] = Right(Me.OpenArgs, Len(Me.OpenArgs - x))
End If

In the OpenForm button I have on the primary form, I put the | to
seperate the two to see if it would help me split the string. I get
this error: "Type mismatch" and it highlights: Me.[Entity Type] =
Right(Me.OpenArgs, Len(Me.OpenArgs - x)).

Hope this helps also.
If you haven't populated it yet, then Me.[Entity Name] is going to be null.

What exactly are you passing as the OpenArgs parameter of the OpenForm
method? What are you hoping the InStr function will find?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Steve said:
Dim x As Integer

x = InStr(Me.OpenArgs, Me.[Entity Name])

If Me.NewRecord Then
Me.[Entity Name] = Left(Me.OpenArgs, x)
Me.[Entity Type] = Right(Me.OpenArgs, Len(Me.OpenArgs - x))
End If

This function will lock the strings inputed by another form. Well I
need 2 fields locked with the data, and the only way to do that is by
splitting it. This keeps giving me the error "Invalid use of Null".

Am I doing something wrong?
 
E

e.mel

i need to type faster . . .



e.mel said:
you can also use the split() function. It takes the string, and a
seperator character and spits out an array:

'assume OpenArgs = "One|Two|5ive"

Dim args() As String
args = Split(OpenArgs, "|")

'then
'args(0) = "One"
'args(2) = "Two"
'args(3) = "5ive"



Well, I changed it up enough, here's the code I have now:

Dim x As Integer

x = InStr(Me.OpenArgs, "|")

If Me.NewRecord Then
Me.[Entity Name] = Left(Me.OpenArgs, x)
Me.[Entity Type] = Right(Me.OpenArgs, Len(Me.OpenArgs - x))
End If

In the OpenForm button I have on the primary form, I put the | to
seperate the two to see if it would help me split the string. I get
this error: "Type mismatch" and it highlights: Me.[Entity Type] =
Right(Me.OpenArgs, Len(Me.OpenArgs - x)).

Hope this helps also.
If you haven't populated it yet, then Me.[Entity Name] is going to be null.

What exactly are you passing as the OpenArgs parameter of the OpenForm
method? What are you hoping the InStr function will find?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Dim x As Integer

x = InStr(Me.OpenArgs, Me.[Entity Name])

If Me.NewRecord Then
Me.[Entity Name] = Left(Me.OpenArgs, x)
Me.[Entity Type] = Right(Me.OpenArgs, Len(Me.OpenArgs - x))
End If

This function will lock the strings inputed by another form. Well I
need 2 fields locked with the data, and the only way to do that is by
splitting it. This keeps giving me the error "Invalid use of Null".

Am I doing something wrong?
 
F

fredg

Well, I changed it up enough, here's the code I have now:

Dim x As Integer

x = InStr(Me.OpenArgs, "|")

If Me.NewRecord Then
Me.[Entity Name] = Left(Me.OpenArgs, x)
Me.[Entity Type] = Right(Me.OpenArgs, Len(Me.OpenArgs - x))
End If

In the OpenForm button I have on the primary form, I put the | to
seperate the two to see if it would help me split the string. I get
this error: "Type mismatch" and it highlights: Me.[Entity Type] =
Right(Me.OpenArgs, Len(Me.OpenArgs - x)).

Hope this helps also.
If you haven't populated it yet, then Me.[Entity Name] is going to be null.

What exactly are you passing as the OpenArgs parameter of the OpenForm
method? What are you hoping the InStr function will find?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Steve said:
Dim x As Integer

x = InStr(Me.OpenArgs, Me.[Entity Name])

If Me.NewRecord Then
Me.[Entity Name] = Left(Me.OpenArgs, x)
Me.[Entity Type] = Right(Me.OpenArgs, Len(Me.OpenArgs - x))
End If

This function will lock the strings inputed by another form. Well I
need 2 fields locked with the data, and the only way to do that is by
splitting it. This keeps giving me the error "Invalid use of Null".

Am I doing something wrong?

Where are you placing the code?
If you are filling in a Control's Value it must be in the Load event
or later, not the Open event.

If your passed OpenArgs string looks like this:

Testing Name Entity|HTML Document

Then to read the OpenArgs string, use:

Dim intX as Integer
intX = InStr(Me.OpenArgs,"|")
Me![Entity Name] = Left(Me.OpenArgs,intX - 1)
Me![Entity Type] = Mid(Me.OpenArgs,intX + 1)

Remember to use the intX-1 and +1 values which you have been omitting.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top