LIKE OPERATOR

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

*I am trying to write some code stating that if Me.Division starts with "PK"
then Me.File_ID needs to start with "PK*******"? The *'s have to be filled in
with numbers. How do I write this code in VB?

Thanks,

Q.Hills
 
I know that the *'s have to be filled in with number. Can you help assist me
in writing this code?
 
I am not understanding your question? Are you talking about the numbers that
will have to go where the *'s are located? If so, for example, the numbers
can be PK12345678. Bascially, any numbers can go behind the PK.
 
Yes, thanks. To do this, it needs to be in the After Update event of Division:

Dim lngBigNum as Long

If Left(Me.Division,2) = "PK" Then
Randomize
lngBigNum = Int((99999999 *Rnd) + 1)
Me.File_ID = "PK" & Format(lngBigNum, "00000000")
End If

The code checks to see if Division starts with PK. If it does, it creates a
random number. The NUmber is them formatted so it is always 8 characters
long. Then the literal PK and the formated number are concatenated and used
to populate the File_ID text box.
 
I think you're trying to concatinate [Division] with numbers entered in text
box on the form?
something like that? [Division]&[textbox1]

Barb
 
No, I am concatenating literal value of "PK" and the results of a call to Rnd
(random number generator) formatted so that the number is always 8 characters
and populating the File_ID control with the concatenated values. So, if
Me.Division starts with "PK" and the random number generator returs 53421,
the result would be "PK00053421"

Barb said:
I think you're trying to concatinate [Division] with numbers entered in text
box on the form?
something like that? [Division]&[textbox1]

Barb

Klatuu said:
Yes, thanks. To do this, it needs to be in the After Update event of Division:

Dim lngBigNum as Long

If Left(Me.Division,2) = "PK" Then
Randomize
lngBigNum = Int((99999999 *Rnd) + 1)
Me.File_ID = "PK" & Format(lngBigNum, "00000000")
End If

The code checks to see if Division starts with PK. If it does, it creates a
random number. The NUmber is them formatted so it is always 8 characters
long. Then the literal PK and the formated number are concatenated and used
to populate the File_ID text box.
 
Hi Klathuu
I see what you're doing, I'm just not sure if that's what QHills meant.
Looks to me like his users will be imputting the numbers through text box -
just confused.

Barb


Klatuu said:
No, I am concatenating literal value of "PK" and the results of a call to Rnd
(random number generator) formatted so that the number is always 8 characters
and populating the File_ID control with the concatenated values. So, if
Me.Division starts with "PK" and the random number generator returs 53421,
the result would be "PK00053421"

Barb said:
I think you're trying to concatinate [Division] with numbers entered in text
box on the form?
something like that? [Division]&[textbox1]

Barb

Klatuu said:
Yes, thanks. To do this, it needs to be in the After Update event of Division:

Dim lngBigNum as Long

If Left(Me.Division,2) = "PK" Then
Randomize
lngBigNum = Int((99999999 *Rnd) + 1)
Me.File_ID = "PK" & Format(lngBigNum, "00000000")
End If

The code checks to see if Division starts with PK. If it does, it creates a
random number. The NUmber is them formatted so it is always 8 characters
long. Then the literal PK and the formated number are concatenated and used
to populate the File_ID text box.

:

I am not understanding your question? Are you talking about the numbers that
will have to go where the *'s are located? If so, for example, the numbers
can be PK12345678. Bascially, any numbers can go behind the PK.

:

I can help if you can tell me how to know what number to use.

:

I know that the *'s have to be filled in with number. Can you help assist me
in writing this code?

:

How do you know what numbers to use?

:

*I am trying to write some code stating that if Me.Division starts with "PK"
then Me.File_ID needs to start with "PK*******"? The *'s have to be filled in
with numbers. How do I write this code in VB?

Thanks,

Q.Hills
 
You have a point. I asked about 3 time where the number comes from and he
said it could be any number.

I guess if you can't ask a good question, you can't expect a good answer.

Barb said:
Hi Klathuu
I see what you're doing, I'm just not sure if that's what QHills meant.
Looks to me like his users will be imputting the numbers through text box -
just confused.

Barb


Klatuu said:
No, I am concatenating literal value of "PK" and the results of a call to Rnd
(random number generator) formatted so that the number is always 8 characters
and populating the File_ID control with the concatenated values. So, if
Me.Division starts with "PK" and the random number generator returs 53421,
the result would be "PK00053421"

Barb said:
I think you're trying to concatinate [Division] with numbers entered in text
box on the form?
something like that? [Division]&[textbox1]

Barb

:

Yes, thanks. To do this, it needs to be in the After Update event of Division:

Dim lngBigNum as Long

If Left(Me.Division,2) = "PK" Then
Randomize
lngBigNum = Int((99999999 *Rnd) + 1)
Me.File_ID = "PK" & Format(lngBigNum, "00000000")
End If

The code checks to see if Division starts with PK. If it does, it creates a
random number. The NUmber is them formatted so it is always 8 characters
long. Then the literal PK and the formated number are concatenated and used
to populate the File_ID text box.

:

I am not understanding your question? Are you talking about the numbers that
will have to go where the *'s are located? If so, for example, the numbers
can be PK12345678. Bascially, any numbers can go behind the PK.

:

I can help if you can tell me how to know what number to use.

:

I know that the *'s have to be filled in with number. Can you help assist me
in writing this code?

:

How do you know what numbers to use?

:

*I am trying to write some code stating that if Me.Division starts with "PK"
then Me.File_ID needs to start with "PK*******"? The *'s have to be filled in
with numbers. How do I write this code in VB?

Thanks,

Q.Hills
 
Something along these lines, perhaps:

If Me.Division.Value Like "PK*" Then
If Me.File_ID.Value Like "PK########*" Then
'All is well
Else
MsgBox "File_ID must begin with PK followed by " _
& vbCrLf & "eight digits."
End If
End If
 
Back
Top