VERY SMALL Help for VBA

  • Thread starter Thread starter sunil
  • Start date Start date
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
 
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
 
Back
Top