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
|
|||
|
|||
Default value depending on previous field
I have a Costing form with a several lines that include fields for Crates and
their Costs. If a user enters a Crate on line 1 (Crate1) the related cost field (Crate1Cost) should then be populated with the amount of 60.00. However, on any lines that are NOT used, the cost should remain at the default of 0.00. In other words, the cost fields should only come alive if the preceding Crate field on that line has been populated. In an earlier post somebody suggested the following code, but unfortunately it has no effect: Private Sub Crate1_AfterUpdate() If Not IsNull(Crate1) Then Crate1Cost = 60 Else Crate1Cost = 0 End If End Sub I'll be grateful for your comments Many thanks CW |
#2
|
|||
|
|||
Default value depending on previous field
That code appears to be a reasonable approach for this problem. Tell us what
"has no effect" means -- no value is written into the Crate1Cost control? wrong value is written into the control? -- Ken Snell MS ACCESS MVP "CW" wrote in message ... I have a Costing form with a several lines that include fields for Crates and their Costs. If a user enters a Crate on line 1 (Crate1) the related cost field (Crate1Cost) should then be populated with the amount of 60.00. However, on any lines that are NOT used, the cost should remain at the default of 0.00. In other words, the cost fields should only come alive if the preceding Crate field on that line has been populated. In an earlier post somebody suggested the following code, but unfortunately it has no effect: Private Sub Crate1_AfterUpdate() If Not IsNull(Crate1) Then Crate1Cost = 60 Else Crate1Cost = 0 End If End Sub I'll be grateful for your comments Many thanks CW |
#3
|
|||
|
|||
Default value depending on previous field
I don't think that the code was meant to be used literally. Go into design
mode of the form. Click on the Crate textbox control and open its properties window. Select [Event Procedure] in the After Update event and click on the . .. button at the end. Now, enter the code provided but change Crate1 and Crate1Cost to the actual names of the form controls. It might help to use "Me." to automatically display the control names. Another way to do this is to set the cost control's Control Source property to something like this: =IIF(IsNull([Crate]),0,60) CW wrote: I have a Costing form with a several lines that include fields for Crates and their Costs. If a user enters a Crate on line 1 (Crate1) the related cost field (Crate1Cost) should then be populated with the amount of 60.00. However, on any lines that are NOT used, the cost should remain at the default of 0.00. In other words, the cost fields should only come alive if the preceding Crate field on that line has been populated. In an earlier post somebody suggested the following code, but unfortunately it has no effect: Private Sub Crate1_AfterUpdate() If Not IsNull(Crate1) Then Crate1Cost = 60 Else Crate1Cost = 0 End If End Sub I'll be grateful for your comments Many thanks CW -- Message posted via AccessMonster.com http://www.accessmonster.com/Uwe/For...forms/200611/1 |
#4
|
|||
|
|||
Default value depending on previous field
The only thing wrong with the code you posted is that the object references
are not qualified. It should work. It is a very common way to do what you want to do. Have you tried tracing the code in debug to see if the event is firing? "CW" wrote: I have a Costing form with a several lines that include fields for Crates and their Costs. If a user enters a Crate on line 1 (Crate1) the related cost field (Crate1Cost) should then be populated with the amount of 60.00. However, on any lines that are NOT used, the cost should remain at the default of 0.00. In other words, the cost fields should only come alive if the preceding Crate field on that line has been populated. In an earlier post somebody suggested the following code, but unfortunately it has no effect: Private Sub Crate1_AfterUpdate() If Not IsNull(Crate1) Then Crate1Cost = 60 Else Crate1Cost = 0 End If End Sub I'll be grateful for your comments Many thanks CW |
#5
|
|||
|
|||
Default value depending on previous field
Several responses to my post already! Everybody is up and at it today!!
Ken, the "non-effect" is that when you enter the Crate field and input something (it's usually a simple decription of the item to be crated, but this has no relevance, is not hooked up to anything else), and then you leave the field, the value on the Cost field remains at 0.00, even if you tab through it and carry on into another line. By virtue of the fact that the Crate field has been populated, the Cost field should have come up with 60.00 (to save people have to type it in manually). Looking fwd to any further ideas... thanks CW "Ken Snell (MVP)" wrote: That code appears to be a reasonable approach for this problem. Tell us what "has no effect" means -- no value is written into the Crate1Cost control? wrong value is written into the control? -- Ken Snell MS ACCESS MVP "CW" wrote in message ... I have a Costing form with a several lines that include fields for Crates and their Costs. If a user enters a Crate on line 1 (Crate1) the related cost field (Crate1Cost) should then be populated with the amount of 60.00. However, on any lines that are NOT used, the cost should remain at the default of 0.00. In other words, the cost fields should only come alive if the preceding Crate field on that line has been populated. In an earlier post somebody suggested the following code, but unfortunately it has no effect: Private Sub Crate1_AfterUpdate() If Not IsNull(Crate1) Then Crate1Cost = 60 Else Crate1Cost = 0 End If End Sub I'll be grateful for your comments Many thanks CW |
#6
|
|||
|
|||
Default value depending on previous field
Let's make a small change in the code (assuming that the controls are named
Crate1 and Crate1Cost): Private Sub Crate1_AfterUpdate() If Not IsNull(Me.Crate1) Then Me.Crate1Cost = 60 Else Me.Crate1Cost = 0 End If Now, let's also be sure that the form knows you have this code attached to the On After Update property of the Crate1 control. Open the form in design view, click on the Crate1 control, open the Properties window, click on Event tab, and look at the On After Update property. Do you see [Event Procedure] in that box? If not, the form does not know that you've added the above code procedure. In that case, click in the box, select [Event Procedure] from the dropdown, and then click on the three-dot button at far right of box. That will connect the code to the property. -- Ken Snell MS ACCESS MVP "CW" wrote in message ... Several responses to my post already! Everybody is up and at it today!! Ken, the "non-effect" is that when you enter the Crate field and input something (it's usually a simple decription of the item to be crated, but this has no relevance, is not hooked up to anything else), and then you leave the field, the value on the Cost field remains at 0.00, even if you tab through it and carry on into another line. By virtue of the fact that the Crate field has been populated, the Cost field should have come up with 60.00 (to save people have to type it in manually). Looking fwd to any further ideas... thanks CW "Ken Snell (MVP)" wrote: That code appears to be a reasonable approach for this problem. Tell us what "has no effect" means -- no value is written into the Crate1Cost control? wrong value is written into the control? -- Ken Snell MS ACCESS MVP "CW" wrote in message ... I have a Costing form with a several lines that include fields for Crates and their Costs. If a user enters a Crate on line 1 (Crate1) the related cost field (Crate1Cost) should then be populated with the amount of 60.00. However, on any lines that are NOT used, the cost should remain at the default of 0.00. In other words, the cost fields should only come alive if the preceding Crate field on that line has been populated. In an earlier post somebody suggested the following code, but unfortunately it has no effect: Private Sub Crate1_AfterUpdate() If Not IsNull(Crate1) Then Crate1Cost = 60 Else Crate1Cost = 0 End If End Sub I'll be grateful for your comments Many thanks CW |
Thread Tools | |
Display Modes | |
|
|