VBA Problem with date

G

Guest

i have a problem ; how to solve that first let give you the table structure
that i have
i
1) [Sno] number
2) [item] Text
3) [Price] number
4) [Date] Date/time

so i want to have a coding on a button on FORM such as

Private Sub Command4_Click()
With Form_Form1.Recordset
..MoveFirst
While (Not .EOF)
If (Form_Form1.item = "apple") Then
Form_Form1.price = 100
End If
..MoveNext
Wend
End With

End Sub

so the above coding do work and give the desire result [Price] 100 for
[tem] Apple
but i want to how to change the item price for a specific date item to 200

or

how to change today's date item apple price to 200
thanks


hope u got i
 
S

Stefan Hoffmann

hi Naveed,

Naveed said:
1) [Sno] number
2) [item] Text
3) [Price] number
4) [Date] Date/time
so the above coding do work and give the desire result [Price] 100 for
[tem] Apple
but i want to how to change the item price for a specific date item to 200

Dim sqlStatement As String

sqlStatement = "UPDATE [yourTable] " & _
"SET [Price] = 100 " & _
"WHERE [Item] = 'Apple'"
CurrentDb.Execute sqlStatement, dbFailOnError
or
how to change today's date item apple price to 200

sqlStatement = "UPDATE [yourTable] " & _
"SET [Price] = 200 " & _
"WHERE [Item] = 'Apple' AND " & _
"[Date] >= DateSerial(Year(Now), Month(Now), Day(Now))"


mfG
--> stefan <--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top