Put this into a class module in your project
VB Code:
  1. Option Explicit
  2.  
  3. Private Type RASDIALPARAMS
  4.    dwSize As Long
  5.    szEntryName(256) As Byte
  6.    szPhoneNumber(128) As Byte
  7.    szCallbackNumber(128) As Byte
  8.    szUserName(256) As Byte
  9.    szPassword(256) As Byte
  10.    szDomain(15) As Byte
  11. End Type
  12.  
  13. Private Declare Function RasDialA Lib "RASAPI32.DLL" (ByVal
  14. lpRasDialExtensions As Long, ByVal lpszPhoneBook As Long, lpRasDialParams As
  15. RASDIALPARAMS, ByVal dwNotifierType As Long, ByVal lpvNotifier As Long,
  16. lphRasConn As Long) As Long
  17. Private Declare Function RasHangUpA Lib "RASAPI32.DLL" (ByVal hRasConn As
  18. Long) As Long
  19.  
  20.  
  21. Public Function RasDial(pEntryName As String, pUsername As String, pPassword
  22. As String, pDomain As String, RasConnection As Long) As Long
  23.    Dim rdp As RASDIALPARAMS
  24.    Dim c As Integer
  25.  
  26.    rdp.dwSize = 1052
  27.  
  28.    For c = 0 To (Len(pUsername) - 1)
  29.       rdp.szUserName(c) = Asc(Mid(pUsername, c + 1, 1))
  30.    Next
  31.    For c = 0 To (Len(pPassword) - 1)
  32.       rdp.szPassword(c) = Asc(Mid(pPassword, c + 1, 1))
  33.    Next
  34.    For c = 0 To (Len(pEntryName) - 1)
  35.       rdp.szEntryName(c) = Asc(Mid(pEntryName, c + 1, 1))
  36.    Next
  37.  
  38.    For c = 0 To (Len(pDomain) - 1)
  39.       rdp.szDomain(c) = Asc(Mid(pDomain, c + 1, 1))
  40.    Next c
  41.  
  42.    'RasDialA will place return code in Connect and return to calling routine
  43.    RasDial = RasDialA(0&, 0&, rdp, 0&, 0&, RasConnection)
  44.  
  45. End Function
  46.  
  47. Public Function RasHangUp(RasConnection As Long) As Long
  48.    RasHangUp = RasHangUpA(RasConnection)
  49. End Function
  50.  
  51. In you project do this:
  52. Private Sub ConnectDun()
  53.         ' DunName is the name of your phone book entry to use
  54.         Username = "JAMES"
  55.         PassWord = "BOND"
  56.         Domain = "MI5"
  57.         lReturnCode = dun.RasDial(DunName, UserName,PassWord, "DOMAIN",
  58. gRASConn)
  59.         If lReturnCode <> 0 Then
  60.             lReturnCode = dun.RasHangUp(gRASConn)
  61.             ModemConnected = 0
  62.             MsgBox "Error connecting to " & DunName & " " & lReturnCode
  63.             Exit Sub
  64.         End If
  65. End Sub
  66.  
  67. Private Sub DisconnectDun()
  68.         lReturnCode = dun.RasHangUp(gRASConn)
  69. End Sub