Hi!
I've have a bit of VBA code which I want to execute in a Macro.
My macro is linked to a UI button and serveral other things are run in the same macro.
In the middle of the macro I need to execute a bit of VBA code. I've figured out that I should use macro action "RunCode" but I do not know how I should write the syntax. Every way I try results in an error.
My knowledge on how to write syntax in very limited so I was hoping to get some help here.
The code I'm attempting to execute is in a "module" and it looks like this:
[VBA]Option Compare Database
Function changefieldnames(oldname As String, newname As String)
'----- oldname and newname are passed to this function from
'----- wherever you are in your process. I would do it via a
'----- form, but if the field names you change are the same every
'----- time the process is run, why not store them in a table. The
'----- code you w1ill need to pass the field names to be corrected
'----- from the table is given in Sub readinfieldnames() below.
Dim db As Database
Dim tdf As TableDef
Dim n As Object
Set db = CurrentDb
Set tdf = db.TableDefs("trans1_SMT")
For Each n In tdf.Fields
If n.Name = oldname Then n.Name = newname
Next n
Set tdf = Nothing
Set db = Nothing
End Function
Sub readinfieldnames()
Dim rst_data As Recordset
'------ Assumes you have a table with 2 columns. Column 1 contains
'------- downloaded field names, column 2 has the names you want
Dim oldfieldname As String, newfieldname As String
Set rst_data = CurrentDb.OpenRecordset("conv_FieldNames")
With rst_data
.MoveFirst
Do Until .EOF
oldfieldname = .Fields(0).Value
newfieldname = .Fields(1).Value
changefieldnames oldfieldname, newfieldname
.MoveNext
Loop
End With
Set rst_data = Nothing
End Sub[/VBA]
As you can see there are two pieces of code. The point of all the code is to rename the headers of one of my tables in my access data base.
The error message I get is:
"The expression you entered has a function containing the wrong number of arguments"
My version of MS Access is: MS Access 2003
Thanks in advance for any help!
Regards, Erik