General discussion

Locked

VBA Using Access Form with SQL Data

By twhite ·
I am trying to figure out why the below VB Code is not working. I do not get any errors just an hour glass for a few seconds and then nothing. I tested the SQL script and it returns the correct data. I also tested the VB Code without the SQL script and just imputing the string and it works.

DOESN'T WORK:

Private Sub RDPSystemInfo_Click()
On Error GoTo Err_RDPSystemInfo_Click

Dim WshShell
Dim stAppName As String

stAppName = "SELECT systeminformation.[RDPProfile] " & _
"FROM systeminformation " & _
"WHERE systeminformation.[AccountNumber]=2000;"

Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "mstsc.exe " & stAppName & ""

Exit_RDPSystemInfo_Click:
Exit Sub

Err_RDPSystemInfo_Click:
MsgBox Err.Description
Resume Exit_RDPSystemInfo_Click

End Sub


WORKS:

Private Sub RDPSystemInfo_Click()
On Error GoTo Err_RDPSystemInfo_Click

Dim WshShell
Dim stAppName As String

stAppName = "G:\RDPConnections\CooperPeds.rdp"

Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "mstsc.exe " & stAppName & ""

Exit_RDPSystemInfo_Click:
Exit Sub

Err_RDPSystemInfo_Click:
MsgBox Err.Description
Resume Exit_RDPSystemInfo_Click

End Sub

This conversation is currently closed to new comments.

3 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

by Sheryl V In reply to VBA Using Access Form wit ...

What type of field is systeminformation.[AccountNumber]? if it's a text field you need to clarify ... systeminformation.[AccountNumber]= '2000'"
If you're using Microsoft Access, you might want to make sure a DAO reference exists.
As a slower solution you could always use stAppName = DLookup ("[RDPProfile]", "systeminformation"," &_
"[AccountNumber]= '" & 2000 & "'" )
Good Luck, hope that helps.

Collapse -

by twhite In reply to

Thanks a bunch that was exactly what I needed I was just drawing a blank.

Collapse -

by twhite In reply to VBA Using Access Form wit ...

This question was closed by the author

Back to Web Development Forum
3 total posts (Page 1 of 1)  

Related Discussions

Related Forums