M
Martureo Bob
Hi:
I'm a newbie and have implemented some code to update a database field using
DAO 3.6 --- that code is working. For example, the following will set the
field named [Receipt Comment Identifier] to a value
of 1:
' These "DIM" statements appear in the Declarations section
Dim daoDatabase As DAO.Database
Dim daoRecordSet As DAO.Recordset
' This command to open the database is done once at the beginning
' In the following, note that the path to database
' is passed in shortcut after /cmd
Set daoDatabase = OpenDatabase(Command)
' Code like this appears many times throughout the module for various
fields
Set daoRecordSet = daoDatabase.OpenRecordset("Report Options Table")
With daoRecordSet
' Enter edit mode
.Edit
' Change data in edit buffer
' Do not print the "tear off slip"
![Receipt Comment Identifier] = 1
' Save changes and close the recordset
.Update
.Close
End With
In order to streamline the module, here's what I'm trying to accomplish...
I want to create a Function within the module to which I can pass the table
name (like "Report Options Table"), the field name (like [Receipt Comment
Identified]) and the value to be set (like 1). This sub would then perform
something like the above sequence to perform the desired database update.
Something like this:
Private Function Update_Field ( _
Table_Name as Variant, _
Field_Name as Variant, _
Value_Name as Variant _
)
Set daoRecordSet = daoDatabase.OpenRecordset(Table_Name)
With daoRecordSet
' Enter edit mode
.Edit
' Change data in edit buffer
!Field_Name = Value_Name '<--this is invalid
' Save changes and close the recordset
.Update
.Close
End With
End Function
But I cannot figure out how to code the line that I marked above as
"invalid" --- the system is looking for a field named [Field_Name] rather
than looking in the Field_Name variable to find the field name. I'm sure
this is something simple --- but I'm still fairly new to VBA coding.
Thanks in advance....
Bob
I'm a newbie and have implemented some code to update a database field using
DAO 3.6 --- that code is working. For example, the following will set the
field named [Receipt Comment Identifier] to a value
of 1:
' These "DIM" statements appear in the Declarations section
Dim daoDatabase As DAO.Database
Dim daoRecordSet As DAO.Recordset
' This command to open the database is done once at the beginning
' In the following, note that the path to database
' is passed in shortcut after /cmd
Set daoDatabase = OpenDatabase(Command)
' Code like this appears many times throughout the module for various
fields
Set daoRecordSet = daoDatabase.OpenRecordset("Report Options Table")
With daoRecordSet
' Enter edit mode
.Edit
' Change data in edit buffer
' Do not print the "tear off slip"
![Receipt Comment Identifier] = 1
' Save changes and close the recordset
.Update
.Close
End With
In order to streamline the module, here's what I'm trying to accomplish...
I want to create a Function within the module to which I can pass the table
name (like "Report Options Table"), the field name (like [Receipt Comment
Identified]) and the value to be set (like 1). This sub would then perform
something like the above sequence to perform the desired database update.
Something like this:
Private Function Update_Field ( _
Table_Name as Variant, _
Field_Name as Variant, _
Value_Name as Variant _
)
Set daoRecordSet = daoDatabase.OpenRecordset(Table_Name)
With daoRecordSet
' Enter edit mode
.Edit
' Change data in edit buffer
!Field_Name = Value_Name '<--this is invalid
' Save changes and close the recordset
.Update
.Close
End With
End Function
But I cannot figure out how to code the line that I marked above as
"invalid" --- the system is looking for a field named [Field_Name] rather
than looking in the Field_Name variable to find the field name. I'm sure
this is something simple --- but I'm still fairly new to VBA coding.
Thanks in advance....
Bob