Results 1 to 6 of 6
  1. #1
    Forbes's Avatar
    Forbes is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Mar 2017
    Posts
    133

    Sending Shell cmds

    So I just threw some stuff together based off what I know, the problem is I cannot get the string to recognize the Text portion, in fact it's like it ignores it all together



    Example:

    Code:
    Private Sub cmdSubmit_Click()Dim CMDLineCommand As String
    CMDLineCommand = " echo " & Me.txtView.Text & " > log.txt "
    ShellRun ("cmd.exe /c " & CMDLineCommand)
    End Sub
    What it's doing:

    cmd.exe /c echo > log.txt

    Completely skipping over my txtbox text, any suggestions?

  2. #2
    Forbes's Avatar
    Forbes is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Mar 2017
    Posts
    133
    I have also ran it this way with the same result

    Code:
    Private Sub cmdSubmit_Click()
    Dim CMDLineCommand As String
    Dim within As String
    Me.txtView.SetFocus
    within = Me.txtView.Text
    CMDLineCommand = " echo " & within & " > log.txt "
    ShellRun ("cmd.exe /c " & CMDLineCommand)
    End Sub

  3. #3
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,016
    Sorry...wrong post!
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  4. #4
    InsuranceGuy is offline Competent Performer
    Windows 7 64bit Access 2016
    Join Date
    Aug 2015
    Location
    Colorado
    Posts
    126
    Add a debug statement to test the value of me.txtView.Text.

    Something like:
    Code:
    within = Me.txtView.Text
    msgbox "within = " & within
    If you don't get the desired result in the message box, you're not referring to your object accurately. Change it, retest, after getting what you want, take out the Msgbox debug statement.

    Cheers,

    Jeff

  5. #5
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I just created a form with a text box on it; named the text box control "txtView".
    Created a button named "cmdSubmit".
    tried to add the code you posted.... would not compile. "ShellRun" is not a valid VBA command.
    Changed the command to "Shell".
    Code:
    Private Sub cmdSubmit_Click()
        Dim CMDLineCommand As String
        CMDLineCommand = " echo " & Me.txtView & " > log.txt "
        MsgBox CMDLineCommand
        Shell ("cmd.exe /c " & CMDLineCommand)
        '     ShellRun ("cmd.exe /c " & CMDLineCommand)
    End Sub
    Entered "Help" into the text box.
    Clicked the button.

    A text file named "log.txt" was created.

  6. #6
    Forbes's Avatar
    Forbes is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Mar 2017
    Posts
    133
    Thank you! With help from everyone I was able to make this work great, special thanks to ssanfu!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 7
    Last Post: 02-26-2013, 02:26 PM
  2. Combining 'sending mail' with 'sending a report'.
    By Mattbro in forum Programming
    Replies: 2
    Last Post: 11-25-2012, 07:42 AM
  3. wait and shell
    By maxbre in forum Programming
    Replies: 19
    Last Post: 11-03-2011, 11:10 AM
  4. Using Shell in VBA
    By ghutche in forum Programming
    Replies: 7
    Last Post: 03-17-2011, 10:13 AM
  5. Call Shell() syntax
    By jgelpi16 in forum Programming
    Replies: 6
    Last Post: 03-07-2011, 02:56 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums