By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,098 Members | 1,116 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,098 IT Pros & Developers. It's quick & easy.

Run Regedit from Access form

P: n/a
I want to run regedit and write a key from an event in a form in a more
generic manner than the way I have done it here which is:

RunReg = Shell("regedit.exe /s I:\APPFolder\SQLfix.reg", 0)

The Access Application that I am running it from is in the folder
I:\AppFolder.

I am thinking something like this, but I am a bit unsure here if the
inverted commas are right.

RunReg = Shell("regedit.exe /s " & CurrentProject.Path & "\SQLfix.reg", 0)

I am unable to test this here. Can someone please comment on the quotation
marks in the generic version?

dixie
Nov 13 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
The quotation marks appear to be good as long as there are no spaces in the
path or file name. If there are, it may need to look more like:

RunReg = Shell("regedit.exe /s """ & CurrentProject.Path & "\SQLfix.reg""",
0)

To put quotes around the Path\FileName. Shell sometimes gets picky about
extra quotes in the command line, so you'll need to test this with the file
placed in a folder that has a space in its name. Assuming Shell doesn't balk
at the extra quotes, they should work whether or not there is a space in the
Path\FileName.

--
Wayne Morgan
MS Access MVP
"dixie" <di***@dogmail.com> wrote in message
news:42********@duster.adelaide.on.net...
I want to run regedit and write a key from an event in a form in a more
generic manner than the way I have done it here which is:

RunReg = Shell("regedit.exe /s I:\APPFolder\SQLfix.reg", 0)

The Access Application that I am running it from is in the folder
I:\AppFolder.

I am thinking something like this, but I am a bit unsure here if the
inverted commas are right.

RunReg = Shell("regedit.exe /s " & CurrentProject.Path & "\SQLfix.reg", 0)

I am unable to test this here. Can someone please comment on the
quotation marks in the generic version?

dixie

Nov 13 '05 #2

P: n/a
Ah, thanks Wayne, that is what I thought. I tried putting two lots of
double quotation marks in but it would not accept it. I need it generic
enough to deal with spaces as I have not control over what users have called
their folders. What I needed was 3 sets of quotation marks - I've always
had difficulties working out how many and why.

dixie

"Wayne Morgan" <co***************************@hotmail.com> wrote in message
news:zs*******************@newssvr30.news.prodigy. com...
The quotation marks appear to be good as long as there are no spaces in
the path or file name. If there are, it may need to look more like:

RunReg = Shell("regedit.exe /s """ & CurrentProject.Path &
"\SQLfix.reg""", 0)

To put quotes around the Path\FileName. Shell sometimes gets picky about
extra quotes in the command line, so you'll need to test this with the
file placed in a folder that has a space in its name. Assuming Shell
doesn't balk at the extra quotes, they should work whether or not there is
a space in the Path\FileName.

--
Wayne Morgan
MS Access MVP
"dixie" <di***@dogmail.com> wrote in message
news:42********@duster.adelaide.on.net...
I want to run regedit and write a key from an event in a form in a more
generic manner than the way I have done it here which is:

RunReg = Shell("regedit.exe /s I:\APPFolder\SQLfix.reg", 0)

The Access Application that I am running it from is in the folder
I:\AppFolder.

I am thinking something like this, but I am a bit unsure here if the
inverted commas are right.

RunReg = Shell("regedit.exe /s " & CurrentProject.Path & "\SQLfix.reg",
0)

I am unable to test this here. Can someone please comment on the
quotation marks in the generic version?

dixie


Nov 13 '05 #3

P: n/a
The reason for 3 is because in order to include the delimiter, in this case
a quote, in the string that is being delimited, you have to double them up.
There has to be a way to tell VBA that you don't intend for THAT quote to be
a delimiter.

Example:
"""", this is a string with a quote as the only character in the output (").
The outside quotes are the delimiters. The double quotes in the middle tell
VBA that this one is to be treated literally.

--
Wayne Morgan
MS Access MVP
"dixie" <di***@dogmail.com> wrote in message
news:42********@duster.adelaide.on.net...
Ah, thanks Wayne, that is what I thought. I tried putting two lots of
double quotation marks in but it would not accept it. I need it generic
enough to deal with spaces as I have not control over what users have
called their folders. What I needed was 3 sets of quotation marks - I've
always had difficulties working out how many and why.

Nov 13 '05 #4

P: n/a
Wayne, sorry, but I still don't get it.

RunReg = Shell("regedit.exe /s """ & CurrentProject.Path & "\SQLfix.reg""",
0)

Why is the triple qoute around the 2nd and 4th instances and not the 1st and
3rd instances of quotes. It makes more sense to me to have them around all
of them?

dixie

"Wayne Morgan" <co***************************@hotmail.com> wrote in message
news:fn*****************@newssvr12.news.prodigy.co m...
The reason for 3 is because in order to include the delimiter, in this
case a quote, in the string that is being delimited, you have to double
them up. There has to be a way to tell VBA that you don't intend for THAT
quote to be a delimiter.

Example:
"""", this is a string with a quote as the only character in the output
("). The outside quotes are the delimiters. The double quotes in the
middle tell VBA that this one is to be treated literally.

--
Wayne Morgan
MS Access MVP
"dixie" <di***@dogmail.com> wrote in message
news:42********@duster.adelaide.on.net...
Ah, thanks Wayne, that is what I thought. I tried putting two lots of
double quotation marks in but it would not accept it. I need it generic
enough to deal with spaces as I have not control over what users have
called their folders. What I needed was 3 sets of quotation marks - I've
always had difficulties working out how many and why.


Nov 13 '05 #5

P: n/a
Anytime you have multiple quotes in a row, each pair ("") translates to ".
In what Wayen gave you, the first part "regedit.exe /s """ equates to the
string regedit.exe /s ": the double quotes translate to a quote, and you've
got the whole thing within quotes. Similarly, the final part "\SQLfix.reg"""
translates to the string \SQLfix.reg" In other words, if CurrentProject.Path
is, say, C:\My Application, you'll end up with the string

regedit.exe /s "C:\My Application\SQLfix.reg"
--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

"dixie" <di***@dogmail.com> wrote in message
news:42********@duster.adelaide.on.net...
Wayne, sorry, but I still don't get it.

RunReg = Shell("regedit.exe /s """ & CurrentProject.Path &
"\SQLfix.reg""",
0)

Why is the triple qoute around the 2nd and 4th instances and not the 1st
and 3rd instances of quotes. It makes more sense to me to have them
around all of them?

dixie

"Wayne Morgan" <co***************************@hotmail.com> wrote in
message news:fn*****************@newssvr12.news.prodigy.co m...
The reason for 3 is because in order to include the delimiter, in this
case a quote, in the string that is being delimited, you have to double
them up. There has to be a way to tell VBA that you don't intend for THAT
quote to be a delimiter.

Example:
"""", this is a string with a quote as the only character in the output
("). The outside quotes are the delimiters. The double quotes in the
middle tell VBA that this one is to be treated literally.

--
Wayne Morgan
MS Access MVP
"dixie" <di***@dogmail.com> wrote in message
news:42********@duster.adelaide.on.net...
Ah, thanks Wayne, that is what I thought. I tried putting two lots of
double quotation marks in but it would not accept it. I need it generic
enough to deal with spaces as I have not control over what users have
called their folders. What I needed was 3 sets of quotation marks -
I've always had difficulties working out how many and why.



Nov 13 '05 #6

P: n/a
Dixie,

Another way to look at it would be to use a mix of single and double quotes.
If you change
RunReg = Shell("regedit.exe /s """ & CurrentProject.Path &
"\SQLfix.reg""",
0)


to

RunReg = Shell("regedit.exe /s '" & CurrentProject.Path & "\SQLfix.reg'", 0)

would it make more sense to you? This would put a single quote around the
path. You have to delimit the string with quotes, but when it gets passed
VBA removes the quotes, leaving (using C:\Folder for the path)

regedit.exe /s 'C:\Folder\SQLfix.reg'

In most cases, this is acceptable, but there are some things that don't like
the single quotes. When you run across one of those, you need to find a way
to "force" the double quotes in (since Access is using them to find the
beginning and end of the string(s) you can't just put them in as normal,
there has to be a different method to distinguish between the two -
delimiter or literal quote in the string). One good example of when this is
needed is when doing a search of a Last Name field. If you place single
quotes around the field, then names such as O'Hare will cause your code to
crash because the single quote in the name causes a problem with the single
quotes around the name.

The above could also be written this way to get the double quote in instead
of using a single quote.

RunReg = Shell("regedit.exe /s " & Chr(34) & CurrentProject.Path &
"\SQLfix.reg" & Chr(34), 0)

Using the double quote is easier to type than Chr(34), but it can be harder
to read and is definitely harder to count to make sure that you have them
all matched up.

I would suggest playing with this in the Immediate Window and see what gets
returned.

Example:
?"This is a test string"
This is a test string

?"This is "" a test string"
This is " a test string

This will show you what is actually being passed once VBA removes the
delimiter quotes. The delimiter quotes tell VBA that this is a string, once
they've done that, they've done their job and aren't needed any longer. So,
they're removed. If they weren't and you assigned the value to a textbox,
the text would still have the quotes around it in the textbox instead of
just the text being there.

--
Wayne Morgan
MS Access MVP
Nov 13 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.