Microsoft Access Forums

Go Back   Microsoft Access Forums > Access Forums > Access

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 03-25-2009, 09:17 AM
hhuuhn hhuuhn is offline Windows XP Access 2003 (version 11.0)
Novice
 
Join Date: Mar 2009
Posts: 14
hhuuhn is on a distinguished road
Default compile error variable not defined VB code, Access97

Hello,
what I intend to do is data quality cotrol whatever is selected from combobox( Yes, No, NA), if NA selected then the next several fields will be skipped (disabled). i use the follwoing code, it doesn't work, it works the same code in other field. i don't know why. i would appreciate if any one can help me find out. thanks a lot

Private Sub change_smoking_AfterUpdate()
If (Me![change smoking].Value <> "1") Or (Me![change smoking].Value <> "0") Then
Me![Ceased smoking].Enabled = no
Me![Ceased smoking].Value = " "
Me![ReducedSmoking].Enabled = no
Me![ReducedSmoking].Value = ""
Me![IncreasedSmoking].Enabled = no
Me![IncreasedSmoking].Value = ""
Else
Me![Ceased smoking].Enabled = (Me![change smoking].Value = "1") Or (Me![change smoking].Value = "0")
Me![Ceased smoking].Value = " "
Me![ReducedSmoking].Enabled = (Me![change smoking].Value = "1") Or (Me![change smoking].Value = "0")
Me![ReducedSmoking].Value = ""
Me![IncreasedSmoking].Enabled = (Me![change smoking].Value = "0") Or (Me![change smoking].Value = "1")
Me![IncreasedSmoking].Value = ""
End If
End Sub
Reply With Quote
  #2  
Old 03-25-2009, 03:32 PM
RuralGuy's Avatar
RuralGuy RuralGuy is online now Windows 7 Access 2007 (version 12.0)
Administrator
 
Join Date: Mar 2007
Location: 8300' in the Colorado Rocky Mountains
Posts: 4,263
RuralGuy will become famous soon enoughRuralGuy will become famous soon enough
Default

Which line does the debugger highlight?
__________________
(RG for short) aka Allan Bunch MS Access MVP - WinXP Pro, Win7 - acXP, ac07
If your issue is resolved...follow this link for directions on how to use the Solved thread tool!
Teaching is not filling a bucket but lighting a fire. Borrowed quote..."Docendo discimus"
Reply With Quote
  #3  
Old 03-25-2009, 05:44 PM
rommelgenlight rommelgenlight is offline Windows XP Access 2003 (version 11.0)
Advanced Beginner
 
Join Date: Mar 2009
Posts: 77
rommelgenlight is on a distinguished road
Default

when you are using ".enabled", its value should only be true or false, yes or no, 0 or -1.

you don't let ms access decide for itself to choose either true or false. you are to set it by yourself. on your example

" Me![Ceased smoking].Enabled = (Me![change smoking].Value = "1") Or (Me![change smoking].Value = "0") "

here you see you use "OR" for ms access to decide for itself whether to decide 1 or 0.
you are to set it by yourself.
Reply With Quote
  #4  
Old 03-26-2009, 05:18 AM
hhuuhn hhuuhn is offline Windows XP Access 2003 (version 11.0)
Novice
 
Join Date: Mar 2009
Posts: 14
hhuuhn is on a distinguished road
Default

Thanks.
But when i put "False" instead of "no", it blocks all next 3 fields whether you select Yea, or no, or NA. When I use "no", it has error message and the code
Private Sub change_smoking_AfterUpdate()
has highlighted for debugging.
I have used the same code many times in the same DB, I can't figure out why this one doesn't work.
Thanks a lot for your help!
Reply With Quote
  #5  
Old 03-26-2009, 05:45 AM
RuralGuy's Avatar
RuralGuy RuralGuy is online now Windows 7 Access 2007 (version 12.0)
Administrator
 
Join Date: Mar 2007
Location: 8300' in the Colorado Rocky Mountains
Posts: 4,263
RuralGuy will become famous soon enoughRuralGuy will become famous soon enough
Default

Strange line to highlight. What error are you getting?
__________________
(RG for short) aka Allan Bunch MS Access MVP - WinXP Pro, Win7 - acXP, ac07
If your issue is resolved...follow this link for directions on how to use the Solved thread tool!
Teaching is not filling a bucket but lighting a fire. Borrowed quote..."Docendo discimus"
Reply With Quote
  #6  
Old 03-26-2009, 06:34 AM
hhuuhn hhuuhn is offline Windows XP Access 2003 (version 11.0)
Novice
 
Join Date: Mar 2009
Posts: 14
hhuuhn is on a distinguished road
Default

the error message box show
Compile error: variable not defined
When I tick OK , Private Sub change_smoking_AfterUpdate() highlighted in yellow(debug) and the first no highlighted in blue as regular highlighter.
I tried to put False instead of no in the code, no error message appear, but it disabled all next 3 fields regardless what selected....
basically if Yes(1), or No(0) selected then the next 3 fields need to filled out, if NA(8) selected then no need to enter these 3 fields( skepped).

I changed the code as below:
Private Sub change_smoking_AfterUpdate()
If Me![change smoking].Value = "8" Then
Me![Ceased smoking].Enabled = False
Me![Ceased smoking].Value = " "
Me![ReducedSmoking].Enabled = False
Me![ReducedSmoking].Value = ""
Me![IncreasedSmoking].Enabled = False
Me![IncreasedSmoking].Value = ""
Else
.........
(the rest code same as previous)
also doesn't work...

Thank you so much RuralGuy !
Reply With Quote
  #7  
Old 03-26-2009, 07:08 AM
RuralGuy's Avatar
RuralGuy RuralGuy is online now Windows 7 Access 2007 (version 12.0)
Administrator
 
Join Date: Mar 2007
Location: 8300' in the Colorado Rocky Mountains
Posts: 4,263
RuralGuy will become famous soon enoughRuralGuy will become famous soon enough
Default

I would comment out this entire procedure and type it in again to see if there is some corruption.
__________________
(RG for short) aka Allan Bunch MS Access MVP - WinXP Pro, Win7 - acXP, ac07
If your issue is resolved...follow this link for directions on how to use the Solved thread tool!
Teaching is not filling a bucket but lighting a fire. Borrowed quote..."Docendo discimus"
Reply With Quote
  #8  
Old 03-26-2009, 07:10 AM
RuralGuy's Avatar
RuralGuy RuralGuy is online now Windows 7 Access 2007 (version 12.0)
Administrator
 
Join Date: Mar 2007
Location: 8300' in the Colorado Rocky Mountains
Posts: 4,263
RuralGuy will become famous soon enoughRuralGuy will become famous soon enough
Default

I forgot to say: Start the entire event coding sequence again from the "..." button.
__________________
(RG for short) aka Allan Bunch MS Access MVP - WinXP Pro, Win7 - acXP, ac07
If your issue is resolved...follow this link for directions on how to use the Solved thread tool!
Teaching is not filling a bucket but lighting a fire. Borrowed quote..."Docendo discimus"
Reply With Quote
  #9  
Old 03-26-2009, 07:17 AM
rommelgenlight rommelgenlight is offline Windows XP Access 2003 (version 11.0)
Advanced Beginner
 
Join Date: Mar 2009
Posts: 77
rommelgenlight is on a distinguished road
Default

can you tell us what now is your whole afterupdate() code! By the way, is your change_smoking field is a text type format or a number format?

or you said, you have used your code on your other db's. on your present db, are the field names still the same as you used here on your code?
Reply With Quote
  #10  
Old 03-26-2009, 07:33 AM
hhuuhn hhuuhn is offline Windows XP Access 2003 (version 11.0)
Novice
 
Join Date: Mar 2009
Posts: 14
hhuuhn is on a distinguished road
Default

OK,
I removed all the code and started event procedure at "..." button and typed code cerycarefully to avoid typo, still blocked all 3 field regardless what selected. no error message.
code below:
Private Sub change_smoking_AfterUpdate()
If Me![change smoking].Value = "8" Then
Me![Ceased smoking].Enabled = False
Me![Ceased smoking].Value = " "
Me![ReducedSmoking].Enabled = False
Me![ReducedSmoking].Value = ""
Me![IncreasedSmoking].Enabled = False
Me![IncreasedSmoking].Value = ""
Else
Me![Ceased smoking].Enabled = (Me![change smoking].Value = "1") Or (Me![change smoking].Value = "0")
Me![ReducedSmoking].Enabled = (Me![change smoking].Value = "1") Or (Me![change smoking].Value = "0")
Me![IncreasedSmoking].Enabled = (Me![change smoking].Value = "1") Or (Me![change smoking].Value = "0")
Me![Ceased smoking].Value = " "
Me![ReducedSmoking].Value = ""
Me![IncreasedSmoking].Value = ""
End If
End Sub

Any clue to try other coding?
Thanks soooooo much!
Reply With Quote
  #11  
Old 03-26-2009, 07:41 AM
hhuuhn hhuuhn is offline Windows XP Access 2003 (version 11.0)
Novice
 
Join Date: Mar 2009
Posts: 14
hhuuhn is on a distinguished road
Default

Change_smoking is a text format, but i linked with number in look up table (1=Yes,0=no,8=NA) I mean I have coded same way for many other fields in the same DB. i understand I need to change the field name all the time when do the different field...
Reply With Quote
  #12  
Old 03-26-2009, 07:47 AM
RuralGuy's Avatar
RuralGuy RuralGuy is online now Windows 7 Access 2007 (version 12.0)
Administrator
 
Join Date: Mar 2007
Location: 8300' in the Colorado Rocky Mountains
Posts: 4,263
RuralGuy will become famous soon enoughRuralGuy will become famous soon enough
Default

Quote:
Originally Posted by hhuuhn View Post
OK,
I removed all the code and started event procedure at "..." button and typed code cerycarefully to avoid typo, still blocked all 3 field regardless what selected. no error message.
So at least we have resolved the error message? I'll take a look at the code now.
__________________
(RG for short) aka Allan Bunch MS Access MVP - WinXP Pro, Win7 - acXP, ac07
If your issue is resolved...follow this link for directions on how to use the Solved thread tool!
Teaching is not filling a bucket but lighting a fire. Borrowed quote..."Docendo discimus"
Reply With Quote
  #13  
Old 03-26-2009, 07:50 AM
RuralGuy's Avatar
RuralGuy RuralGuy is online now Windows 7 Access 2007 (version 12.0)
Administrator
 
Join Date: Mar 2007
Location: 8300' in the Colorado Rocky Mountains
Posts: 4,263
RuralGuy will become famous soon enoughRuralGuy will become famous soon enough
Default

Quote:
Originally Posted by hhuuhn View Post
Change_smoking is a text format, but i linked with number in look up table (1=Yes,0=no,8=NA) I mean I have coded same way for many other fields in the same DB. i understand I need to change the field name all the time when do the different field...
So the Change_smoking field is a Numeric field? What type? Integer, Long, Single, Double, Currency?
__________________
(RG for short) aka Allan Bunch MS Access MVP - WinXP Pro, Win7 - acXP, ac07
If your issue is resolved...follow this link for directions on how to use the Solved thread tool!
Teaching is not filling a bucket but lighting a fire. Borrowed quote..."Docendo discimus"
Reply With Quote
  #14  
Old 03-26-2009, 07:51 AM
rommelgenlight rommelgenlight is offline Windows XP Access 2003 (version 11.0)
Advanced Beginner
 
Join Date: Mar 2009
Posts: 77
rommelgenlight is on a distinguished road
Default

if it is a number format base on your lookup table, then your change_smoking.value must be a number and not text format like what you've done such as "8", "1", "0". it should only be 8,0 or 1. and like i've said you cannot make ms access decide for itself what to choose between two values there in your OR statement. you should assign one value.
Reply With Quote
  #15  
Old 03-26-2009, 07:58 AM
RuralGuy's Avatar
RuralGuy RuralGuy is online now Windows 7 Access 2007 (version 12.0)
Administrator
 
Join Date: Mar 2007
Location: 8300' in the Colorado Rocky Mountains
Posts: 4,263
RuralGuy will become famous soon enoughRuralGuy will become famous soon enough
Default

It looks to me like Change_smoking can *only* be 0,1 or 8. Is that true? Having fun answering two people at the same time?
__________________
(RG for short) aka Allan Bunch MS Access MVP - WinXP Pro, Win7 - acXP, ac07
If your issue is resolved...follow this link for directions on how to use the Solved thread tool!
Teaching is not filling a bucket but lighting a fire. Borrowed quote..."Docendo discimus"
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Variable Criteria JamesLens Queries 0 01-02-2009 01:55 PM
Possible to store user-defined types in table? Binky Programming 0 11-20-2008 11:28 AM
permision problem with access97 dourvas Access 0 11-04-2008 03:07 AM
Variable question synapse5150 Programming 1 07-09-2008 06:17 AM
"Debug Error!" and crash while editting code or form Dan Herrick Access 4 04-20-2006 10:30 PM


All times are GMT -8. The time now is 02:39 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.