Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / August 2008

Tip: Looking for answers? Try searching our database.

If Len(txt_PCode) <> cbo_PName

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
shiro - 12 Aug 2008 13:04 GMT
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
BruceM - 12 Aug 2008 13:46 GMT
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.

>I have code on before update event of my form,
> but can't work.The form's data source is DProd_tbl.
[quoted text clipped - 26 lines]
>
> Shiro
shiro - 13 Aug 2008 08:39 GMT
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

> 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
[quoted text clipped - 44 lines]
> >
> > Shiro
BruceM - 13 Aug 2008 12:20 GMT
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?

> Oh I'm sorry Bruce,
> I mean "Len MName" data type is Number.So,
[quoted text clipped - 60 lines]
>> >
>> > Shiro
shiro - 14 Aug 2008 02:53 GMT
txt_PCode is text and it always change everyday.The thing that is not
change is number of the character (it's len).

> 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:
[quoted text clipped - 72 lines]
> >> >
> >> > Shiro
BruceM - 14 Aug 2008 12:07 GMT
What exactly are you trying to do?  Explain in non-Access terms, please.

> txt_PCode is text and it always change everyday.The thing that is not
> change is number of the character (it's len).
[quoted text clipped - 81 lines]
>> >> >
>> >> > Shiro
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.