TransferDatabase to a variable name

G

Guest

I am trying to copy a table out to a dbf which works fine. The thing I am
having a little problem with is make the file name a variable. Here's what
I'm using:

Function COPYtoSVR()
On Error GoTo COPYtoSVR_Err
Dim WhoID As String
WhoID = UCase(Left(fOSUserName(), 3))
DoCmd.TransferDatabase acExport, "dBase III", "M:\", acTable, "MASTER",
WhoID + ".dbf", False


COPYtoSVR_Exit:
Exit Function

COPYtoSVR_Err:
MsgBox Error$
Resume COPYtoSVR_Exit

End Function

You might notice that I am using the fosUserName function that was offered
on the discussion group. Do you see what I am doing wrong. I want to save
each person's work under their username.dbf.

Thanks in advance.
 
D

Dirk Goldgar

Bonnie said:
I am trying to copy a table out to a dbf which works fine. The thing
I am having a little problem with is make the file name a variable.
Here's what I'm using:

Function COPYtoSVR()
On Error GoTo COPYtoSVR_Err
Dim WhoID As String
WhoID = UCase(Left(fOSUserName(), 3))
DoCmd.TransferDatabase acExport, "dBase III", "M:\", acTable,
"MASTER", WhoID + ".dbf", False


COPYtoSVR_Exit:
Exit Function

COPYtoSVR_Err:
MsgBox Error$
Resume COPYtoSVR_Exit

End Function

You might notice that I am using the fosUserName function that was
offered on the discussion group. Do you see what I am doing wrong.
I want to save each person's work under their username.dbf.

Thanks in advance.

What sort of problem are you having? That code works fine for me, once
I fix the line break that I assume was introduced by the newsreader when
you posted it.
 
G

Guest

Hi Dirk,

Thanks for responding. I just get "there was an error executing a command."
I'm wondering if maybe I'm not finding the module. Is there a rule as to
where the module should be? I have a module named: COPYtoSVR and the
function name is COPYtoSVR. Could that be the problem?

Thanks again.
 
G

Guest

I got it Dirk. For some reason when I called the function from a Macro it
works.

Thanks for your help.
 
D

Dirk Goldgar

Bonnie said:
Hi Dirk,

Thanks for responding. I just get "there was an error executing a
command." I'm wondering if maybe I'm not finding the module. Is
there a rule as to where the module should be? I have a module
named: COPYtoSVR and the function name is COPYtoSVR. Could that be
the problem?

The module and function should not have the same name. That could be
the source of at least some problems, though the error message you
quoted isn't specific to it. Name the module something else, even if
it's just by prefixing its name with "mod" (for "module").
 
D

Dirk Goldgar

Bonnie said:
I got it Dirk. For some reason when I called the function from a
Macro it works.

That's a workaround I hadn't heard of. But I'd still rename the module,
if I were you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top