Link to home
Start Free TrialLog in
Avatar of fatalerror080298
fatalerror080298

asked on

VBScript Trying to Connect to MS Access 97 DB

I am trying to connect to an Access database using VBScript in Outlook 98.  It seems like the code is connecting to the database but it says "Record(s) can't be read; no read permission on 'tblEmployee'".  How in VBScript would I pass it a username and password?
Avatar of fatalerror080298
fatalerror080298

ASKER

Edited text of question
did you make sure that the database is not read-only???
What code do you have so far?
No, the database isn't read only but even if it was I should still be able to select from it.  I just wouldn't be able to change anything.

I will post the code first thing Monday morning.  I am at home so I don't have it in front of me.  Sorry about that....  I should have posted it in the first place.

Thanks...
As you can see this is fired off when they press a command button.

Sub Submit_Click
          'Set the location of the database
      SetDatabaseLocation("y:\eclaims.mdb")

      'Initialize Outlook Variables
      InitializeOutlookVariables

      'Open the database
      OpenDatabase
      
      'Get the SQL statement ready
      strSQL = "SELECT * FROM tblEmployee;"
      Set MyRS = myDb.OpenRecordset(strSQL)
.......
         ---Some other code to do something with the data
End Sub

sub OpenDatabase
      'Initialize DAO
      on error resume next
      Set dbe = item.application.CreateObject("DAO.DBEngine.35")
      if err.Number <> 0 Then
          MsgBox "There is an error with the data access components. " & Chr(13) _
          & "Please contact the Help Desk at ext. xxx.", vbOKOnly + VBExclamation,                                                                "Data Access Error"
          ErrorDetected = 1
          Exit Sub
      End If

      Set myDb = dbe.workspace(0).OpenDatabase(DatabaseLocation, False, False,                                  "MS Access;USR=joeblow;PWD=password")
      If Err.Number <> 0 Then
           MsgBox "There is an error with the Help Desk at ext. xxx." & Chr(13) _
           & "Please contact your Administrator", vbOKOnly + VBExclamation,                       "Database Access Error"
           ErrorDetected = 1
           Exit Sub
      End If
End Sub

Sub InitializeOutlookVariables
      set oNameSpace = Application.GetNameSpace("MAPI")
End Sub

sub SetDatabaseLocation(Location)
      DatabaseLocation = Location
end sub
Sorry about the formatting on that.  It didn't come out very good after I hit the submit button.
Oops...  The above line in Sub OpenDatabase should have read:

Set myDb = dbe.OpenDatabase(DatabaseLocation, False, False, "MS Access;UID=sa;PWD=pass")
Have you checked permissions on the table in Access?
Yea, that was one of the first things I looked at.  I can log in directly to the database using the same username and password as my program is using and it works just fine.
ASKER CERTIFIED SOLUTION
Avatar of tomook
tomook

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial