If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Access > how to run code in Current record ?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #16 (permalink)  
Old 02-01-12, 01:46
oMADMANo oMADMANo is offline
Registered User
 
Join Date: Jan 2012
Posts: 16
The objects are part of a form which does uses single form view. I am trying to apply the code to the current record only to make the objects visible when the tick box is selected on that record. They are not stored values in my table.
Reply With Quote
  #17 (permalink)  
Old 02-01-12, 02:45
Sinndho Sinndho is offline
Registered User
 
Join Date: Mar 2009
Posts: 3,446
Missinglinq formerly provided the code needed to do what you want:
Code:
Private Sub RiskAssesment_AfterUpdate()
   If Me.RiskAssesment.Value = -1 Then
     Me.Risk.Visible = True
   Else
     Me.Risk.Visible = False
   End If
End Sub
You answered that "the code does not work", which is not very helpful. What kind of problem (error, unexpected result, ...) did you encouter when trying to use it?
__________________
Have a nice day!
Reply With Quote
  #18 (permalink)  
Old 02-01-12, 03:41
oMADMANo oMADMANo is offline
Registered User
 
Join Date: Jan 2012
Posts: 16
when I used that code when I select or de-select the tick box it does nothing (including no error). the tick box has a yes/no property and default is zero so I tried using the value of 1 and 2 but still didn't work. I think that code could
work but something must be wrong.
Reply With Quote
  #19 (permalink)  
Old 02-01-12, 04:50
Sinndho Sinndho is offline
Registered User
 
Join Date: Mar 2009
Posts: 3,446
Please check that the code is effectively linked to the event. In Design view, select the control "RiskAssesment", open the Properties window , select the Event tab and verify that the "After Update" line displays "[Event Procedure]" (see attachment)
Attached Thumbnails
how to run code in Current record ?-event_properties.jpg  
__________________
Have a nice day!
Reply With Quote
  #20 (permalink)  
Old 02-01-12, 06:20
oMADMANo oMADMANo is offline
Registered User
 
Join Date: Jan 2012
Posts: 16
Yeh its all linked up. I have tried after update and on click with them both in properties (one at a time) I still got no result when I clicked the tick box.
Reply With Quote
  #21 (permalink)  
Old 02-02-12, 04:56
oMADMANo oMADMANo is offline
Registered User
 
Join Date: Jan 2012
Posts: 16
please can you lot share some more advice on this I am still stuck
Reply With Quote
  #22 (permalink)  
Old 02-02-12, 05:36
Sinndho Sinndho is offline
Registered User
 
Join Date: Mar 2009
Posts: 3,446
Quote:
Originally Posted by oMADMANo View Post
when I used that code when I select or de-select the tick box it does nothing (including no error). the tick box has a yes/no property and default is zero so I tried using the value of 1 and 2 but still didn't work. I think that code could work but something must be wrong.
A checkBox in Access (what you name a "tick box") can only have two values: True (= -1) when it is "ticked" (i.e. a check mark is visible) and False (= 0) when it is not "ticked". It can also be Null (which is not a value) when it is greyed. Testing for any other values is meaningless, although any non-zero value can be considered as True.

Please post an exact copy of the code for the Sub procedure "RiskAssesment_AfterUpdate()" as it is in your database.
__________________
Have a nice day!
Reply With Quote
  #23 (permalink)  
Old 02-02-12, 06:20
healdem healdem is online now
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,250
for the sake of pedantry
you shouldn't test check boxes with numeric values. in an ideal world you should test with the intrinsic vb(s) constants
vbtrue
vbfalse
why?
you don't know if Microsoft will change the way boolean values are represented in future
similarly you don't know if other db vendors will change the way they store boolean values. strictly speaking Access is a front end user interface tool, not a database per se, the defautl dataabase in Access is JET but through various reasons not all of 'em good many people assume that Access = JET = Access.
you can test for NULL by using the function isnull()
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #24 (permalink)  
Old 02-02-12, 14:10
oMADMANo oMADMANo is offline
Registered User
 
Join Date: Jan 2012
Posts: 16
okay i have took your advice to use vbfalse / vbtrue but i don't think i fully understand how to use them. i have tried this
Code:
Private Sub RiskAssesment_AfterUpdate()

 Set db = CurrentDb
 Set rs = db.OpenRecordset("Membership Database", dbOpenDynaset)
    
   
   
   If vbFalse(rs![RiskAssesment]) Then
     Me.Risk.Visible = False
       
   ElseIf vbTrue(rs![RiskAssesment]) Then
     Me.Risk.Visible = True
    
   End If

End Sub
but i get error saying "Expected array"
Please help.
Reply With Quote
  #25 (permalink)  
Old 02-02-12, 16:10
Sinndho Sinndho is offline
Registered User
 
Join Date: Mar 2009
Posts: 3,446
1. vbFalse and vbTrue are constants, not functions. You use them in comparison expressions such as:
Code:
If MyVariable = vbTrue Then
or:
Code:
If Me.SomeControl.Value = vbFalse Then
2. Why do you try to open a Recordset to retrieve a value from its RiskAssesment field ? Moreover, the value you get is to one of the first row in the Recordset, not the row corresponding to the current record of the form.
__________________
Have a nice day!
Reply With Quote
  #26 (permalink)  
Old 02-02-12, 16:59
Sam Landy Sam Landy is offline
Registered User
 
Join Date: May 2004
Location: New York State
Posts: 931
Code:
   If vbFalse(rs![RiskAssesment]) Then
     Me.Risk.Visible = False
       
   ElseIf vbTrue(rs![RiskAssesment]) Then
     Me.Risk.Visible = True
    
   End If
Why don't you simply say
Code:
Me.Risk.Visible = rs![RiskAssesment
(see my original post in the beginning of this thread) Then you won't have to worry about ifs, thens, or boolean representation?

Sam
Reply With Quote
  #27 (permalink)  
Old 02-04-12, 07:10
oMADMANo oMADMANo is offline
Registered User
 
Join Date: Jan 2012
Posts: 16
SOLVED ! thank you all.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On