Check void textbox on each unpaid order

emdiesse

Registered User.
Local time
Today, 00:24
Joined
Feb 1, 2006
Messages
36
I have a table called tblOrders and within that I have
Field | Data Type | Comments
ID | Number | Customers ID.
OrderID | Number | Orders ID, Primary Key.
DatePlaced | Date/Time | Date the order was placed.
DateRequired | Date/Time | Date the order is required
Paid | Boolean | Has the customer paid?
Cancelled | Boolean | Has the order been cancelled?

I would like to be able to create a macro to apply to a button so that when it is clicked it will check to see if the DateRequire = the actual date and if the Paid field is un checked.

If this is correct I would like it to check all of the cancelled checkboxes on each record that meets this criteria.

How do I do this?

Thanks.
 
you dont use a macro. push Alt+11 to get to the codebehind. then write the code in the button's _click event

Code:
dim rs as dao.recordset
set rs = currentdb.openrecordset("[COLOR="Red"]tblOrders[/COLOR]")
if not (rs.bof and rs.eof) then
    rs.movelast
    rs.movefirst
end if

do until rs.eof
    with rs
        if .fields("[COLOR="red"]DateRequire[/COLOR]").Value = Format(Now(),"[COLOR="red"]mm/dd/yyyy[/COLOR]") ' format the mm dd yyyy to however your date is stored
            .fields("[COLOR="red"]Cancelled[/COLOR]").value = true
        else 
            .fields("[COLOR="red"]Cancelled[/COLOR]").value = false
        end if
        .movenext
    end with
loop

rs.close
set rs = nothing

that should do it, this assumes that your check box on the form is linked to a yes/no field on the table; also Now() is the current day/time today- what i assumed to be your "Actual date"; furthermore, this unchecks any checkboxes where the two dates dont match, if you dont want that, then take out the else statement. note that everything in red you should change to fit your preference
 
Last edited:

Users who are viewing this thread

Back
Top Bottom