VERY SMALL Help for VBA

S

sunil

Hello All,

Private Sub Form_Load()
Dim rstDoc As Object
Set rstDoc = CurrentDb.OpenRecordset("CodeTable")
If rstDoc.StartDate = "1/1/1111" Then

'update startdate to present date

MsgBox (rstDoc.RecordCount)
rstDoc.Edit
rstDoc.Update
MsgBox ("hai")
End If
End Sub
this is what i want to do
 
D

Dirk Goldgar

sunil said:
Hello All,

Private Sub Form_Load()
Dim rstDoc As Object
Set rstDoc = CurrentDb.OpenRecordset("CodeTable")
If rstDoc.StartDate = "1/1/1111" Then

'update startdate to present date

MsgBox (rstDoc.RecordCount)
rstDoc.Edit
rstDoc.Update
MsgBox ("hai")
End If
End Sub
this is what i want to do

That pseudo-code doesn't actually make it clear what you want to do.
There could be multiple records in "CodeTable"; do you want to update
all those with the StartDate field = #1/1/1111#? If you do, the whole
job could be more easily accomplished by executing an update query in
code. Is StartDate a text field (as implied by your code) or a
date/time field? Assuming it's a date/time field, and that you want to
update all records with that StartDate, code might look like:

Dim db As DAO.Database

Set db = CurrentDb

db.Execute _
"UPDATE CodeTable SET StartDate = Date() " & _
"WHERE StartDate=#1/1/1111#;", _
dbFailOnError

MsgBox "Updated " & db.RecordsAffected & " records."

Set db = Nothing
 

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