Solved

VBScript Trying to Connect to MS Access 97 DB

Posted on 1999-01-29
10
247 Views
Last Modified: 2013-12-25
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?
0
Comment
Question by:fatalerror080298
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 

Author Comment

by:fatalerror080298
ID: 1499635
Edited text of question
0
 

Expert Comment

by:meetze
ID: 1499636
did you make sure that the database is not read-only???
0
 
LVL 9

Expert Comment

by:TTom
ID: 1499637
What code do you have so far?
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

Author Comment

by:fatalerror080298
ID: 1499638
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...
0
 

Author Comment

by:fatalerror080298
ID: 1499639
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
0
 

Author Comment

by:fatalerror080298
ID: 1499640
Sorry about the formatting on that.  It didn't come out very good after I hit the submit button.
0
 

Author Comment

by:fatalerror080298
ID: 1499641
Oops...  The above line in Sub OpenDatabase should have read:

Set myDb = dbe.OpenDatabase(DatabaseLocation, False, False, "MS Access;UID=sa;PWD=pass")
0
 
LVL 9

Expert Comment

by:TTom
ID: 1499642
Have you checked permissions on the table in Access?
0
 

Author Comment

by:fatalerror080298
ID: 1499643
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.
0
 
LVL 4

Accepted Solution

by:
tomook earned 100 total points
ID: 1499644
In DAO, the password is best applied at the Workspace level. So replace
Set myDb = dbe.OpenDatabase(DatabaseLocation, False, False, "MS Access;UID=sa;PWD=pass")

with

Set MyWS = dbe.CreateWorkspace("SomeName", "sa", "pass", dbUseJet)
Set myDb = MyWS.OpenDatabase(DatabaseLocation)


0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question