Solved Use of Option Box to change field value on click or After Update (1 Viewer)

hbrehmer

Member
Local time
Today, 08:05
Joined
Jan 10, 2020
Messages
78
Hi All,
I have a Option Box with two click options. Numbers 1 and 2 are assigned. I need the click on 1 option to change the value of two fields (status Id's), and the click on option to the change those same to fields to another value. Here what I've written to try and change the fields, but in my test runs the code doesn't updates the values. What am I missing?

In the After Update Event of the Option Group:
=IIf([ShipStatus]=1,[ODStatusID]=4 & [OrderStatusID]=3,[ODStatusID]=5 & [OrderStatusID]=4)

The form data is a query, but I using the query to add new records, but it is also supposed to change the value of the status's. I would post my database, but at this point it is very large.

Any suggestions would be appreciated.

Thank you!
Heidi
 

June7

AWF VIP
Local time
Today, 07:05
Joined
Mar 9, 2014
Messages
5,468
Expression like that in event property will not set value of field. Select [Event Procedure] in the event property then click the ellipses (…) to open VBA editor. In the procedure type:

Me!ODStatusID = IIf(Me.ShipStatus=1, 4, 5)
Me!OrderStatusID = IIf(Me.ShipStatus = 1, 3, 4)
 

cheekybuddha

AWF VIP
Local time
Today, 16:05
Joined
Jul 21, 2014
Messages
2,274
Hello Heidi,

When you click an option radio button the value is assigned to the containing frame.

You can use the Change or AfterUpdate event of the frame to run code to change your fields:
Code:
Private Sub ShipStatus_AfterUpdate()

  Select Case Me.ShipStatus
  Case 1
    Me.ODStatusID = 4
    Me.OrderStatusID = 3
  Case 2
    Me.ODStatusID = 5
    Me.OrderStatusID = 4
  End Select

End Sub

You will need to set the AfterUpdate property of the ShipStatus option frame to: [Event Procedure]

hth,

d
 

hbrehmer

Member
Local time
Today, 08:05
Joined
Jan 10, 2020
Messages
78
Hello Heidi,

When you click an option radio button the value is assigned to the containing frame.

You can use the Change or AfterUpdate event of the frame to run code to change your fields:
Code:
Private Sub ShipStatus_AfterUpdate()

  Select Case Me.ShipStatus
  Case 1
    Me.ODStatusID = 4
    Me.OrderStatusID = 3
  Case 2
    Me.ODStatusID = 5
    Me.OrderStatusID = 4
  End Select

End Sub

You will need to set the AfterUpdate property of the ShipStatus option frame to: [Event Procedure]

hth,

d
OMG! I totally forgot about using the Case function. That will work. Thank you so much for solving my issue. I am getting better at programming, thanks to wonderful people like you. So glad I have this forum for a reference.
 

cheekybuddha

AWF VIP
Local time
Today, 16:05
Joined
Jul 21, 2014
Messages
2,274
You're welcome!

June's solution will work in the same way, and is even more compact. If you were to add more options then the Select Case is a better construct.

The trick is to trigger the update using the event.

👍

d
 

Users who are viewing this thread

Top Bottom