Converting A String To A Command

J

Jeff G

All -

I've modified a module that sends an object in Access 2007. Where my
problem is...on a Form where I'm collecting data to pass through to the
Function, I need to convert the string into a command, if that makes sense.

The command in the module is...

DoCmd.OutputTo OutputType, ItemName, AttachmentType,
"C:\Temp\DatabaseExport\" & AttachmentName & "." & AttachmentExtension

The function is...
EMailAttachment(ItemName As String, OutputType As String, AttachmentName As
String, AttachmentType As String, AttachmentExtension As String,
ReceipientEMail As String, EMailSubject As String, EMailMessage As String)

The problem comes in where the OutputType is being collected as a String
(i.e. "acOutputQuery"), but I need to change it to a command (i.e.
acOutputQuery), basically stripping it of the quotes.

Any help would be greatly appreciated.

Jeff G
 
K

Klatuu

Is isn't clear to me what you are trying to accomplish, but look in VBA help
for the Eval() function. It may be what you want.
 
J

Jeff G

Chris -

I'm using TempVars in a macro to pass the variables to the function. If I
don't put the name in quotes, it assumes it's a field and puts brackets
around it. When you run the macro, it comes back and says it can't find the
name. That's why I'm assuming that these are Strings in the Macro's
TempVar's that need to be converted.
 
J

Jeff G

What I'm trying to accomplish is to use a Function that I can pass variables
back to, instead of have to keep re-using the same code over and over. All
of the variables are being passed from a Macro's TempVar, but they have to
be Strings, unless I'm mistaken. But, then OutputType cannot be a String.
 
K

Klatuu

acOutputQuery is not a command, it is an instrinsic constant. That is, a
define constant value built into Access. Read a bit about constants in VBA
Help.
The purpose of contstants is to make values understandable to we human types.

For example, the value of acOutputQuery is 1. A computer easily understands
1 in the context where it is used, but we humans would have a hard time
remembering all the numeric options, so when we see acOutputQuery, we know
from the ac part it is an Access contstant and the rest means we are going to
output a query.

Sort of like True and False. They are not commands, they are contstants
True = -1 False = 0

As to whether it is a problem it being a number or a string in the macro, I
think it will work. If not, you can use the actual value of 1. Since I
never use queries, I can't tell you for sure how it works.
 
S

Stefan Hoffmann

hi Jeff,

Jeff said:
The problem comes in where the OutputType is being collected as a String
(i.e. "acOutputQuery"), but I need to change it to a command (i.e.
acOutputQuery), basically stripping it of the quotes.
Use a Select Case statement:

Dim OutputObjectType As Access.AcOutputObjectType

Select Case yourString
Case Is = "acOutputQuery"
OutputObjectType = acOutputQuery
Case Is = "acOutputForm"
OutputObjectType = acOutputForm
Case...
End Select

DoCmd.OutputTo OutputObjectType, ...


mfG
--> stefan <--
 

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