alwayshouston
MIS
Hi All
I would like to know how to dynamically update a field declared in ADO recordset? Let me explain what I am trying to do. I have a few tables in my database that has Date_Created field. I would like to update Date_Created Field in all tables dynamically. I have written the code to do this for only Employee table as below:
Dim cnnLocal As New ADODB.Connection
Dim rstCurr As New ADODB.Recordset
Set cnnLocal = CurrentProject.Connection
rstCurr.Open "Select * from Employee", cnnLocal, adOpenKeyset, adLockPessimistic
With rstCurr
Do Until .EOF
!Date_Created.Value = Now()
Loop
End With
rstCurr.Close
How can I do this for few other tables in database such as Customers, Products etc...? I get an error if I try to get to update rstCurr field name with a variable. Ideally, I should have create a procedure as below, but my below procedure gives me an error:
Sub Main()
Call Date_Created ("Employee","Date_Created")
Call Date_Created ("Products", "Date_Created")
Call Date_Created ("Customers", "Date_Created")
etc.....
End Sub
Sub Date_Created( tblName as String, fldName as String)
Dim cnnLocal As New ADODB.Connection
Dim rstCurr As New ADODB.Recordset
Set cnnLocal = CurrentProject.Connection
rstCurr.Open "Select * from " & tblName, cnnLocal, adOpenKeyset, adLockPessimistic
With rstCurr
Do Until .EOF
! & fldName & ".Value" = Now() '<<< Error here
Loop
End With
rstCurr.Close
End Sub
Thanks in Advance!!!
I would like to know how to dynamically update a field declared in ADO recordset? Let me explain what I am trying to do. I have a few tables in my database that has Date_Created field. I would like to update Date_Created Field in all tables dynamically. I have written the code to do this for only Employee table as below:
Dim cnnLocal As New ADODB.Connection
Dim rstCurr As New ADODB.Recordset
Set cnnLocal = CurrentProject.Connection
rstCurr.Open "Select * from Employee", cnnLocal, adOpenKeyset, adLockPessimistic
With rstCurr
Do Until .EOF
!Date_Created.Value = Now()
Loop
End With
rstCurr.Close
How can I do this for few other tables in database such as Customers, Products etc...? I get an error if I try to get to update rstCurr field name with a variable. Ideally, I should have create a procedure as below, but my below procedure gives me an error:
Sub Main()
Call Date_Created ("Employee","Date_Created")
Call Date_Created ("Products", "Date_Created")
Call Date_Created ("Customers", "Date_Created")
etc.....
End Sub
Sub Date_Created( tblName as String, fldName as String)
Dim cnnLocal As New ADODB.Connection
Dim rstCurr As New ADODB.Recordset
Set cnnLocal = CurrentProject.Connection
rstCurr.Open "Select * from " & tblName, cnnLocal, adOpenKeyset, adLockPessimistic
With rstCurr
Do Until .EOF
! & fldName & ".Value" = Now() '<<< Error here
Loop
End With
rstCurr.Close
End Sub
Thanks in Advance!!!