PASSPORT Knowledge Base
Macros

Date Published: January 12, 2005
Date Updated: July 24, 2008

Title

Passing User ID and Password to Startup Macro from Database Lookup

Product

PASSPORT PC to Host, PASSPORT Web to Host

Emulation Types

TN3270, TN5250, VT, SCO ANSI, Wyse 60

Issue

Is it possible to lookup UserID and Password information from a database and pass them to a startup macro?

Solution

Below is a sample macro that will lookup the UserID and Password from a Microsoft Access or SQL Server database based on the current computer name. The following criteria must be met for this macro to work:

Sub ZMain()

Dim Text, ret, Comp, conn1, Source, Connect, Userid, PW                                      

  'Create the database object:

    Set conn1 = CreateObject("ADODB.Recordset")

 

  'Set variable for computer name:

    Comp = Environ("COMPUTERNAME")

 

  'Select record from Users table:

    Source = "SELECT * FROM Users WHERE (((Computer)= '" & Comp & " '));"

 

  'Set variable for connection string to database using valid userid and password:

    Connect = "DSN=MySystemDSN;UID=admin;PWD=;"

 

  'Open connection to database:

    conn1.Open Source, Connect

 

  'Set variable for value of Userid field:

    Userid = conn1.Fields.Item("Userid").Value

 

  'Set variable for value of Password field:

    PW = conn1.Fields("Password").Value

 

  'Send retrieved data to host:

    SendHostKeys Userid

    SendHostKeys ("<ENTER>")

    WaitForNoX 10

    SendHostKeys PW

    SendHostKeys ("<ENTER>")

    

  'Close connection and reset database object:

    conn1.Close

    Set conn1 = Nothing

End Sub

 

Once the macro above has been created, it can be set as a startup macro by following

the steps below:

For PASSPORT PC to Host:

  1. Start a PASSPORT session.
  2. Choose the Communications®Disconnect menu command.
  3. Choose the Communications®Setup menu command.
  4. Select the Miscellaneous tab.
  5. Enable the Startup Macro check box.
  6. Click the Browse button and select the appropriate macro.
  7. Click Connect to save and test.

For PASSPORT Web to Host:

  1. Start the PASSPORT Web to Host Administrator program.
  2. Open the session to configure.
  3. Select the Miscellaneous tab.
  4. Enable the Startup Macro check box.
  5. Choose the appropriate macro from the drop-down list.
  6. Click OK to save or Connect to test.

More Information

Keywords

macro, user id, password, database, lookup, login