If Len(txt_PCode) <> cbo_PName

S

shiro

I have code on before update event of my form,
but can't work.The form's data source is DProd_tbl.
Which have 2 fields :pCode and PName.

On my form,there are txt_PCode and cbo_PName
..The selected value of cboPName is saved to the
field PName.The row source of cbo_PName is from
another table (MName_tbl) which have 2 fields:
MName and Len MName.(MName data type is Number)

I want to control the number of character being
inputted to the txt_PCode must be same with the value
on the column(1) of cbo_PName (column 1 is MName)
so I write the code:

If Len(Me.txt_PCode) <> Me.cbo_PName.Column(1) Then
Cancel = True
MsgBox "Invalid PCode"
Else
End If

But it always invalid although the len of the character =
value on column(1) of cbo_PName.

What's wrong?Hope some like to advise.
tHANK'S

Rgds,

Shiro
 
B

BruceM

It's hard to follow what you are doing. MName is a number, but what is is
Len MName? Is it another field in the table, derived from the length of
MName? If so, you should calculate the value as needed rather than storing
it. The way I see it, if MName is 987, Len MName is 3. Is that correct?

You could try something like this as a test:

MsgBox Len(Me.txt_PCode) & "; " & Len(Me.cbo_PName)

If Len(Me.txt_PCode) <> Len(Me.cbo_PName) Then
Cancel = True
MsgBox "Invalid PCode"
End If

Or you could set a break point at the start of the code and step through it
checking the values as you go. Let me know if you need clarification on how
to do that.
 
S

shiro

Oh I'm sorry Bruce,
I mean "Len MName" data type is Number.So,
actually I want to compare the value of
txt_PCode with the value of "Len MName".
(Len MName is on the cbo_PName Column (1)).
Hope that make a sense.
Thank's

Rgds,

Shiro
 
B

BruceM

If you are trying to compare two numeric values, don't use Len, which looks
at the length of the value (the number of characters it contains). Try:

If (Me.txt_PCode) <> Me.cbo_PName.Column(1) Then
Cancel = True
MsgBox "Invalid PCode"
Else
End If

However, if the data is already in one field, and you are essentially
requiring the user to copy the value to another field, what is the point?
 
S

shiro

txt_PCode is text and it always change everyday.The thing that is not
change is number of the character (it's len).
 

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