Launch VNC with specified Host from MS Access


New member
OK, so I'm at a bit of a loss here.
I've got an Access database and form with all the company's computers on it. What I wanna do is get my button to launch RealVNC to connect to the HostName specified in a control on my form.
I've tried the following:
Private Sub btnVNC_Click()
On Error GoTo Err_btnVNC_Click
    'Copy the computer's HostName
    SendKeys "^{C}", True
    'Run VNC Viewer
    Dim stAppName As String
    stAppName = "C:\Program Files\RealVNC\VNC4\vncviewer.exe"
    Call Shell(stAppName, 1)
    'Paste the computer's HostName and press enter.
    AppActivate (Shell(stAppName, vbNormalFocus))
    SendKeys "^{V}", True
    SendKeys "{ENTER}", True
    Exit Sub
    MsgBox Err.Description
    Resume Exit_btnVNC_Click
End Sub
But all that happens is Access launches RealVNC but says Invalid procedure call or arguement. I have a feeling SendKeys isn't working, as when I paste, the HostName is not pasted.

I can't use DDE as my control is bound to a column in my database.

Can someone help please!
Forgot to remark the "Call Shell(..." line in my copied text - it's remarked in my code, so Shell is not called twice.
I am not sure what version of VB you are running. But, you could try and remove the outer parenthesis from the call to AppActivate:

AppActivate Shell(stAppName, vbNormalFocus)
Nope. Just noticed that when I go
SendKeys "^{C}"
it replaces the text I'm copying with "5050".
Access launches VNC with no problem, but as soon as SendKeys tries to talk to VNC, it brings-up the error.
I really don't think it's a problem with the call procedure, as when I omit the SendKeys, there's no error.
Is there an alternative to SendKeys or maybe a sure-fire tested way of sending keystrokes?
OR, does anyone know if (Like some desktop shortcuts) you can specify the Host in the shortcut properties?
Something like:
stAppName = "C:\Program Files\RealVNC\VNC4\vncviewer.exe /host=" & txtHost.Text
Call Shell(stAppName, 1)

Many thanks for your patience and help so far though!
Last edited: