update by date range and if received (which is a date) value is null
Right now I have an access 2007 Multiple Item form which is wizarded off a query with only the Orders table with the criteria- Between [Start Date] and [End Date] , Received is null.
The Form shows all items matching this. I would like to attach a command button and a text box on this form in which i enter the date i would like to date these records to be received to a date i put in the text box, updating the Orders table only for those records that were returned by the query.
I think I know what you want to do. You want to be able to put a Start and End Date into two different fields and then click Update Orders and the date that you want to put into that is the current date that you pushed the button?
If so here is what you're going to need to do:
First create the two Text Control boxes (Those are the ones that allow you to put something into a field. Please make sure that the wizard function on the form is turned off, otherwise it's going to be asking you questions about what you want to do with each field and the button on the form.
Please name the first TextControl txtStartDate.
Please name the Second TextControl txtEndDate
Please name the Button Control btnUpdateOrders
www.joepottschmidt.com/example1.htm
Then copy and paste this code into your Subroutine that is for the Button Click event.
-
-
Private Sub btnUpdateOrders_Click()
-
-
'-----------------------------------------------------------------------------------------------------------------
-
'Copy from the top of this line down to just before the End Sub
-
'-----------------------------------------------------------------------------------------------------------------
-
Dim MyDB as DAO.Database
-
Dim MyRS as DAO.Recordset
-
-
Set MyDB = CurrentDB()
-
Set MyRS = MyDB.OpenRecordset("SELECT * FROM [Table Name] " & _
-
"WHERE OrderDate = #" & me.txtStartDate & "# AND #" & me.txtEndDate & "#", dbOpenDynaset)
-
-
With MyRS
-
Do While Not .EOF
-
.Edit
-
!TheNameOfTheDateFieldThatYouWantToChange = me.TxtTheDate
-
'This is the field that you want to update as well as the
-
' field on the form that you want to enter the date of these orders.
-
.Update
-
.MoveNext
-
Loop
-
End With
-
-
MyRS.Close
-
MyDB.Close
-
-
Set MyRS = nothing
-
Set MyDB = Nothing
-
'-------------------------------------------------------------------------------------------------------------------
-
'Stop Copying Here
-
--------------------------------------------------------------------------------------------------------------------
-
-
End Sub
-
-
Hope that helps,
Joe P.