Results 1 to 3 of 3
  1. #1
    4 Star Lounger
    Join Date
    Feb 2002
    Posts
    537
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Object required (Access 2000)

    On the basis of my working function wwRemoteCorrect i wanted to build a separate function for initializing
    the remote database, then another function for closing the database and then the core of the function.
    However i cannot do it, since i get the message "Object required" pointing to the line
    db.Execute sqlString from the main function.
    May i get some help as to advising me what is wrong with my function called RemoteCorrect?

    Public Function wwRemoteCorrect()
    Dim StrPassword As String
    StrPassword = "secret"
    Dim wsp As DAO.Workspace
    Dim db As DAO.Database
    Set wsp = DAO.DBEngine.Workspaces(0)
    Set db = wsp.OpenDatabase("C:BEstoreBE.mdb", False, False, ";PWD=" & StrPassword)
    Dim sqlString As String
    sqlString = " Update products SET Branch1 = 0 WHERE branch1 Is Null"
    db.Execute sqlString
    db.Close
    Set db = Nothing
    Set wsp = Nothing
    End Function



    Public Function RemoteCorrect()
    InitializeDb
    Dim sqlString As String
    sqlString = " Update products SET Branch1 = 0 WHERE branch1 Is Null"
    db.Execute sqlString
    DestroyDb
    End Function


    Public Function InitializeDb()
    Dim BEpath As String
    BEpath = "C:bestorebe.mdb"
    Dim StrPassword As String
    StrPassword = "secret"
    Dim wsp As DAO.Workspace
    Dim db As DAO.Database
    Set wsp = DAO.DBEngine.Workspaces(0)
    Set db = wsp.OpenDatabase("C:BEstoreBE.mdb", False, False, ";PWD=" & StrPassword)
    End Function


    Public Sub DestroyDb()
    db.Close
    Set db = Nothing
    End Sub

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Object required (Access 2000)

    If you had had Option Explicit at the top of your module, you would have gotten an error message that the db variable is not defined. You have declared db locally in InitializeDb. It is not known in RemoteCorrect and in DestroyDb.

    One solution is to put the declaration of db at the top of the module, above all Subs and Functions, instead of in InitializeDb:

    Private db As DAO.Database

    Public Function RemoteCorrect()
    ...
    End Function

    Public Function InitializeDb()
    ' don't declare db here!
    ...
    End Function

    Public Sub DestroyDb()
    ...
    End Sub

  3. #3
    4 Star Lounger
    Join Date
    Feb 2002
    Posts
    537
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Object required (Access 2000)

    A nice solution. Thank you very much indeed

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •