Geoff Schultz
Geoff Schultz

Reputation: 151

ByRef argument type mismatch error

I want to call a routine named VBCopyFolder using string variables, but get a "ByRef argument type mismatch" error referencing strOldPath when doing so. I'm a bit lost as how to do this.

VBCopyFolder is defined as:

VBCopyFolder(ByRef strSource As String, ByRef strTarget As String)

and the call that I'm trying to make is:

Dim strOldPath, strNewPath As String
Call VBCopyFolder(strOldPath, strNewPath)

The following works fine:

Call VBCopyFolder("U:\Database\Data.accdb", "Z:\Backups\Data.accdb")

How do I correctly format this call?

Upvotes: 1

Views: 190

Answers (1)

Gord Thompson
Gord Thompson

Reputation: 123809

In VBA,

Dim strOldPath, strNewPath As String

is equivalent to

Dim strOldPath As Variant, strNewPath As String

If you want both variables to be of type String you need to use

Dim strOldPath As String, strNewPath As String

Upvotes: 7

Related Questions