Field Update

J

Jacques Steinman

In one of the previous posts it waas suggested that for field updating based
on a selection I should use the following code:

Private Sub d_itemid_AfterUpdate()

With Me.d_itemid
If Not IsNull(.Value) Then
Me.d_cost = .Column(3)
End If
End With

End Sub

This does the job, but Id like to update more than one field. Can I simply
add another line like this:

Private Sub d_itemid_AfterUpdate()

With Me.d_itemid
If Not IsNull(.Value) Then
Me.d_cost = .Column(3)
Me.d_maxsell = .Column(5)
End If
End With

End Sub

Would this work?
 
D

Douglas J. Steele

Yes, it should work. Why didn't you just try: it would have been far faster
than posting a question and waiting for an answer!

Incidentally, since you're using the Column collection, I assume d_itemid
must be a combo box. The AfterUpdate event will never fire if no record's
been selected, so there's really little point in checking for Null. (The
only reason would be if you're calling that procedure from code elsewhere in
the application). That means all you should need is

With Me.d_itemid
Me.d_cost = .Column(3)
Me.d_maxsell = .Column(5)
End With
 
B

Bob Quintal

=?Utf-8?B?SmFjcXVlcyBTdGVpbm1hbg==?=
In one of the previous posts it waas suggested that for field
updating based on a selection I should use the following code:

Private Sub d_itemid_AfterUpdate()

With Me.d_itemid
If Not IsNull(.Value) Then
Me.d_cost = .Column(3)
End If
End With

End Sub

This does the job, but Id like to update more than one field. Can
I simply add another line like this:

Private Sub d_itemid_AfterUpdate()

With Me.d_itemid
If Not IsNull(.Value) Then
Me.d_cost = .Column(3)
Me.d_maxsell = .Column(5)
End If
End With

End Sub

Would this work?
YES.

It took you longer to compose your message than it would take to
modify and test your code.

Just remember that the index of the column is zero-based, e.g. (0),
(1),(2),(3) refer to columns 1,2,3,4
 
J

Jacques Steinman

Because I encountered a small problem and wanted confirmation before I retry.
If I encounter the same hiccup I'll post it.
 
Top