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. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Urgent code HELP!! Form control visibility by record
Can someone help me with some code? I need to create code that will make a
form's combo box visible or invisible, based on either a check box in the form or its underlying table value (0 or -1). It also has to be record specific, so I know I need to use CurrentRecord in there somewhere. This is what I have, but it doesn't work. Private Sub Form_Current() If Me.chkPaybackApproved = True Then Me.cboApprBy.Visible = True Else Me.cboApprBy.Visible = False End If End Sub Does it need to be in another event? Note that I can't use AfterUpdate, because I'm using a new form based on an older table, so the check boxes have already been updated previously. Thanks!!! -- GD |
#2
|
|||
|
|||
Urgent code HELP!! Form control visibility by record
NEVER MIND!! It's working today, for some reason. Go figure!
-- GD "GD" wrote: Can someone help me with some code? I need to create code that will make a form's combo box visible or invisible, based on either a check box in the form or its underlying table value (0 or -1). It also has to be record specific, so I know I need to use CurrentRecord in there somewhere. This is what I have, but it doesn't work. Private Sub Form_Current() If Me.chkPaybackApproved = True Then Me.cboApprBy.Visible = True Else Me.cboApprBy.Visible = False End If End Sub Does it need to be in another event? Note that I can't use AfterUpdate, because I'm using a new form based on an older table, so the check boxes have already been updated previously. Thanks!!! -- GD |
#3
|
|||
|
|||
Urgent code HELP!! Form control visibility by record
You might have problems on a NewRecord since fields do not yet have a
value... you should also put your code on the control AfterUpdate event so when the dependent value is changed, the code will also be executed '~~~~~~~~~~~~~~~~~~~~~~ Private Sub Form_Current() ShowHideApprBy End Sub '~~~~~~~~~~~~~~~~~~~~~~ Private Sub chkPaybackApproved_AfterUpdate() ShowHideApprBy End Sub '~~~~~~~~~~~~~~~~~~~~~~ Private Sub ShowHideApprBy() If Nz(Me.chkPaybackApproved, False) = True Then Me.cboApprBy.Visible = True Else Me.cboApprBy.Visible = False End If end sub '~~~~~~~~~~~~~~~~~~~~~~ in this case, if the control (field) does not yet have a value, False is assumed from Help '~~~~~~~~~~~~~~~~~~~~~~~~~~`` Nz Function You can use the Nz function to return zero, a zero-length string (" "), or another specified value when a Variant is Null. For example, you can use this function to convert a Null value to another value and prevent it from propagating through an expression. Syntax Nz(variant[, valueifnull]) The Nz function has the following arguments. Argument variant A variable of data type Variant. valueifnull Optional (unless used in a query). A Variant that supplies a value to be returned if the variant argument is Null. This argument enables you to return a value other than zero or a zero-length string. Note If you use the Nz function in an expression in a query without using the valueifnull argument, the results will be a zero-length string in the fields that contain null values. '~~~~~~~~~~~~~~~~~~~~~~~~~~`` the thing to keep in mind when using Nz is what it will return if you don't the specify the second, optional, argument. If you are using Nz on a field, it will be the data type of that field -- 0 for numbers (including dates), and an empty string for text or memo Unbound textbox / combobox / listbox controls on a form are assumed to have TEXT in them... so an empty string will be returned if nothing is specified. And, if you specify something, it doesn't have to be 0 or "" you could do this: NZ(..., "no commision is found in the table for this employee") If you do not specify the optional argument -- If the expression is bound to a text field, an empty string will be returned if the field is null. If the expression is bound to a numeric field, 0 will be returned if the field is null. it is a good idea to wrap return values from dLookup, etc, in NZ in case no match was found .... a good "rule-of-thumb" is to specify the optional arguments (even though it is not necessary) for example: = Nz(DLookup("[Commission]", "Employees" , "[EmpID] = " & nz([EmpID],0)),0 ) notice how NZ is used twice -- once to make sure the criteria will be evaluated, and another time around everything in case dLookup didn't return a value... Warm Regards, Crystal remote programming and training Access Basics 8-part free tutorial that covers essentials in Access http://www.AccessMVP.com/strive4peace * (: have an awesome day * GD wrote: Can someone help me with some code? I need to create code that will make a form's combo box visible or invisible, based on either a check box in the form or its underlying table value (0 or -1). It also has to be record specific, so I know I need to use CurrentRecord in there somewhere. This is what I have, but it doesn't work. Private Sub Form_Current() If Me.chkPaybackApproved = True Then Me.cboApprBy.Visible = True Else Me.cboApprBy.Visible = False End If End Sub Does it need to be in another event? Note that I can't use AfterUpdate, because I'm using a new form based on an older table, so the check boxes have already been updated previously. Thanks!!! |
#4
|
|||
|
|||
Urgent code HELP!! Form control visibility by record
Thanks for the help, Crystal!!
-- GD "strive4peace" wrote: You might have problems on a NewRecord since fields do not yet have a value... you should also put your code on the control AfterUpdate event so when the dependent value is changed, the code will also be executed '~~~~~~~~~~~~~~~~~~~~~~ Private Sub Form_Current() ShowHideApprBy End Sub '~~~~~~~~~~~~~~~~~~~~~~ Private Sub chkPaybackApproved_AfterUpdate() ShowHideApprBy End Sub '~~~~~~~~~~~~~~~~~~~~~~ Private Sub ShowHideApprBy() If Nz(Me.chkPaybackApproved, False) = True Then Me.cboApprBy.Visible = True Else Me.cboApprBy.Visible = False End If end sub '~~~~~~~~~~~~~~~~~~~~~~ in this case, if the control (field) does not yet have a value, False is assumed from Help '~~~~~~~~~~~~~~~~~~~~~~~~~~`` Nz Function You can use the Nz function to return zero, a zero-length string (" "), or another specified value when a Variant is Null. For example, you can use this function to convert a Null value to another value and prevent it from propagating through an expression. Syntax Nz(variant[, valueifnull]) The Nz function has the following arguments. Argument variant A variable of data type Variant. valueifnull Optional (unless used in a query). A Variant that supplies a value to be returned if the variant argument is Null. This argument enables you to return a value other than zero or a zero-length string. Note If you use the Nz function in an expression in a query without using the valueifnull argument, the results will be a zero-length string in the fields that contain null values. '~~~~~~~~~~~~~~~~~~~~~~~~~~`` the thing to keep in mind when using Nz is what it will return if you don't the specify the second, optional, argument. If you are using Nz on a field, it will be the data type of that field -- 0 for numbers (including dates), and an empty string for text or memo Unbound textbox / combobox / listbox controls on a form are assumed to have TEXT in them... so an empty string will be returned if nothing is specified. And, if you specify something, it doesn't have to be 0 or "" you could do this: NZ(..., "no commision is found in the table for this employee") If you do not specify the optional argument -- If the expression is bound to a text field, an empty string will be returned if the field is null. If the expression is bound to a numeric field, 0 will be returned if the field is null. it is a good idea to wrap return values from dLookup, etc, in NZ in case no match was found .... a good "rule-of-thumb" is to specify the optional arguments (even though it is not necessary) for example: = Nz(DLookup("[Commission]", "Employees" , "[EmpID] = " & nz([EmpID],0)),0 ) notice how NZ is used twice -- once to make sure the criteria will be evaluated, and another time around everything in case dLookup didn't return a value... Warm Regards, Crystal remote programming and training Access Basics 8-part free tutorial that covers essentials in Access http://www.AccessMVP.com/strive4peace * (: have an awesome day * GD wrote: Can someone help me with some code? I need to create code that will make a form's combo box visible or invisible, based on either a check box in the form or its underlying table value (0 or -1). It also has to be record specific, so I know I need to use CurrentRecord in there somewhere. This is what I have, but it doesn't work. Private Sub Form_Current() If Me.chkPaybackApproved = True Then Me.cboApprBy.Visible = True Else Me.cboApprBy.Visible = False End If End Sub Does it need to be in another event? Note that I can't use AfterUpdate, because I'm using a new form based on an older table, so the check boxes have already been updated previously. Thanks!!! |
#5
|
|||
|
|||
Urgent code HELP!! Form control visibility by record
you're welcome happy to help
Warm Regards, Crystal remote programming and training Access Basics 8-part free tutorial that covers essentials in Access http://www.AccessMVP.com/strive4peace * (: have an awesome day * GD wrote: Thanks for the help, Crystal!! |
Thread Tools | |
Display Modes | |
|
|