RecordSet, MoveLast? Copy? Apply to Shell command?

VBA-Dummy

Registered User.
Local time
Today, 14:12
Joined
Nov 19, 2004
Messages
15
Lot's going on here, summary: Please excuse my ignorance....
Make table query concatenates three table fields to a new field. F1+F2+F2 = "F1F2F3" in a new field. I need to get that concatenated text string and pass it along as a parameter in an executable. I figure RecordSet is the correct method to get the text, and Shell to pass it on the the executable, but I'm way new to all this.

I've been trying with these statements without sucess:

Code:
Sub Test06()
Dim cn As ADODB.Connection
Dim rs As New ADODB.Recordset
Set cn = CurrentProject.Connection
   'Open the new table, goto last record, last field (hopefully)
    rs.Open "SELECT * FROM Test", cn, adOpenStatic, adLockReadOnly
    rs.MoveLast
   'Ok, if we arrived, like Cntrl+End would do, How do we Cnrtl+C, Copy?

   'Then pass the copied text string ("F1F2F3") as part of the shell command?
Shell("C:\PATH\PROGRAM.EXE /F1F2F3", 1 )  ' << The "F1F2F3" string goes behind the .exe

Set rs = Nothing
Set cn = Nothing
rs.Close
End Sub
 
Try this

Code:
Sub Test06()
Dim cn As ADODB.Connection
Dim rs As New ADODB.Recordset
Set cn = CurrentProject.Connection
   'Open the new table, goto last record, last field (hopefully)
    rs.Open "SELECT * FROM Test", cn, adOpenStatic, adLockReadOnly
    rs.MoveLast
   'Ok, if we arrived, like Cntrl+End would do, How do we Cnrtl+C, Copy?
   
   [COLOR=Red]Dim command_string as string

   command_string = rs("F1") & rs("FE2") & rs("FE3")[/COLOR]

   'Then pass the copied text string ("F1F2F3") as part of the shell command?
Shell("C:\PATH\PROGRAM.EXE /" & [COLOR=Red]command_string[/COLOR], 1 )  ' << The "F1F2F3" string goes behind the .exe

Set rs = Nothing
Set cn = Nothing
rs.Close
End Sub
 
Thanks GoldFinger.
Dim Command_String works fine for "copying" the data in the fields.
However, I can't seen to get the syntax correct for "pasting" the command_string into the Shell statement.

If I set a breakpoint over the Shell statement, and run in the Immediate window:
Code:
?Command_String
msn.com
The result is correct. =msn.com

I've set up a simpler scanerio using Ping.exe, and the Command_String containing the IP address: Like (Ping -t msn.com)

Also in the immediate window, this works fine:
Code:
Shell ("C:\Windows\Ping.exe -t msn.com"), 1

But this does not:
Code:
Shell ("C:\Windows\Ping.exe -t & command_string"), 1

Any ideas what I'm doing incorrectly ??
 
Try moving the closing quotes to match the example:

Shell ("C:\Windows\Ping.exe -t " & command_string), 1
 
i dunno if i understand it the best..But looks like u shud add the sentence
Shell ("C:\Windows\Ping.exe -t " & command_string), 1
 
I had a questiong related to this which i have jus' posted under the thread "Streets and trips". I need to start my Streets and trips application from Access. The path to the Application file is "C:\Program Files\Microsoft Streets and trips". What command should i execute?

Rishi
 
pbaldy said:
Try moving the closing quotes to match the example:

Shell ("C:\Windows\Ping.exe -t ") & command_string, 1

Thanks very much folks. i had to move the ) too.
It works perfectly now!!!

:)
 
Last edited:

Users who are viewing this thread

Back
Top Bottom