Set If Condition (1 Viewer)

learnaccesscg

Registered User.
Local time
Today, 10:46
Joined
Dec 1, 2014
Messages
12
I am trying to have access set a field to true if another field has data.
Example:

If "Delivery Date" field is not null, set a checkbox called "Delivered" to true (Check Checkbox). The reason why I am doing this is client would like a progress type system to see at which stage a package may be ie:
Customer 2: Order Received (Y/N) Order Prepared (Y/N) , Order Shipped (Y/N) , Order Delivered (Y/N), Order Returned (Y/N), Etc. I have a button so that when pressed, the progress can be updated immediately, but would also be interested if it updated on open of form.

Currently, I am trying to use this code, but it does not check the box:

Private Sub Command582_Click()
If Me.DeliveredDate = Not Null Then
'set Me.OrderDelivered = true
End If

' Inform the user
MsgBox "Progress has been refreshed", vbInformation

End Sub

Thank you in advance for your help!

:)
 

Attachments

  • Example.JPG
    Example.JPG
    27.6 KB · Views: 69

Ranman256

Well-known member
Local time
Today, 10:46
Joined
Apr 9, 2015
Messages
4,337
"Me.DeliveredDate = Not Null " is for query use
in code:
if IsNull(Me.DeliveredDate ) then

so
Me.OrderDelivered = not IsNull(Me.DeliveredDate )
 

learnaccesscg

Registered User.
Local time
Today, 10:46
Joined
Dec 1, 2014
Messages
12
Ranman256, Thank you for your comment. I made the adjustment below, but it still doesn't work. The code does not pop up as "debug" which is good but the checkbox does not check.

Private Sub Command582_Click()
If IsNull(Me.DeliveredDate) Then
'Set Me.OrderDelivered = true
End If
' Inform the user
MsgBox "Progress has been refreshed", vbInformation

End Sub
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 22:46
Joined
May 7, 2009
Messages
19,249
or, you can update the table when the form opens:

private sub form_open(cancel as integer)
dim db as dao.database
set db=currentdb
db.execute "Update yourTable Set [OrderDelivered] = True Where (Nz([OrderDelivered], False)=False) And (Not (([DeliveredDate]) Is Null));"
set db=nothing
end sub
 

Minty

AWF VIP
Local time
Today, 15:46
Joined
Jul 26, 2013
Messages
10,380
You don't really need a check box to store this, as you already have the data, eg. if the Delivered date is null then the Delivery isn't made. If it is not null as you have stated then it's been delivered. Also what is some one remove the date (maybe it was entered in error, you would have to make sure that you removed the check box.

Simply use the date or lack of it to present the data accordingly e.g in your query that reports the current status put something like;

DeliveryStatus: IIf(DeliveredDate is Null,"On Route","Delivered on " & DeliveredDate)
 

learnaccesscg

Registered User.
Local time
Today, 10:46
Joined
Dec 1, 2014
Messages
12
Thanks everyone! It ended up working after a few minor changes using what was stated earlier.

I wrote it as:
If me.DeliveredDate >=0 then
me.orderdelivered = -1
else
me.orderdelivered = 0
end If
End Sub

I realized checkbox is coded as -1= true and 0 = false. Is null was not something that it recognized, so I entered as any value greater or = to 0 which worked for a date field. if the date field was empty (null), the check box would remain unchecked. The else statement would allow for if there was any changes to other field.

Now I just have to write in all the other variables and its all complete. The reason why I had to do this is just that the client wanted an easy way to just see check boxes for management but still have the data stored someplace else.

Thanks everyone!
 

Minty

AWF VIP
Local time
Today, 15:46
Joined
Jul 26, 2013
Messages
10,380
Glad you sorted it - you can still create a calculated (virtual) field for the checkbox on a form or report;

CheckDelivered: IIf(DateDelivered >=0, -1 ,0)
 

Users who are viewing this thread

Top Bottom