Results 1 to 3 of 3
  1. #1

    need help with "Dim"

    I am trying to restore an old database our group was using. The original database was not using "Option Explicit" but was working. I want to use "Option Explicit" but I can not get the darn "Dim" correct. Can you please help me and look at the code and determine what the correct type of Dim I should be using for the four Dim at the top of the code? I took a guess with the first four Dim's and I am getting the error message "object variable or with block variable not set" when I run the code but debug and compile does not catch the error. Thanks in advance for your help!

    Private Sub bRepair_Click()
    On Error GoTo errbRepair_Click

    Dim x As Integer 'is this ok?
    Dim DatabasePath As String 'is this ok?
    Dim RepairDB As Database 'this might be the problem
    Dim ret As Reference 'is this ok?

    Dim i As Integer 'I think this is ok?
    Dim Repaired As Recordset 'I think this is ok?
    Dim MySet As Recordset 'I think this is ok?
    Dim MyDb As Database 'I think this is ok?

    Set MyDb = DBEngine.Workspaces(0).Databases(0)
    Set MySet = MyDb.OpenRecordset("tDatabases", DB_OPEN_DYNASET)
    Set Repaired = MyDb.OpenRecordset("tRepairDate", DB_OPEN_TABLE)

    i = 1

    x = MySet.RecordCount

    Do Until i > x
    If Right(MySet!Path, 1) <> "" Then
    DatabasePath = MySet!Path & ""
    DatabasePath = MySet!Path
    End If
    ret = RepairDB(MySet!DriveLetter & DatabasePath & MySet!Database)
    If ret Then
    ret = RepairDB(MySet!DriveLetter & DatabasePath & MySet!Database)
    If ret Then
    MsgBox MySet!DriveLetter & DatabasePath & MySet!Database & " has been Repaired."
    End If
    End If
    i = i + 1

    Repaired.AddNew ' Create new record.
    Repaired("Date") = Now ' Set Date.
    Repaired.Update ' Save changes.



    Exit Sub

    MsgBox Err.Description & "An error occurred while attempting to repair " & MySet!DriveLetter & DatabasePath & MySet!Database & "." & Chr(13) & Chr(13) & " Please ensure the Drive Letter, Path, and Database Name are correct in the Database Listing."
    Exit Sub

    End Sub

  2. #2
    3 Star Lounger
    Join Date
    Mar 2001
    Minneapolis, Minnesota, USA
    Thanked 0 Times in 0 Posts

    Re: need help with

    Do you have the option to Debug when you get the error message? If so, choose to and see what line of code has been highlighted as the offending bit. Post back...
    <font face="Comic Sans MS"><font color=blue>~Shane</font color=blue></font face=comic>

  3. #3
    Plutonium Lounger
    Join Date
    Dec 2000
    Sacramento, California, USA
    Thanked 1 Time in 1 Post

    Re: need help with "Dim"

    You declared this
    <hr>Dim RepairDB As Database 'this might be the problem<hr>
    ... but then you tried this:
    <pre>ret = RepairDB(MySet!DriveLetter & DatabasePath & MySet!Database)</pre>

    Neither Access nor I know what you're trying to do here, since you haven't opened RepairDB as a database at all and since References are objects and have to be instantiated with the Set keyword, so ret can't be a reference object either.

    In fact, I suspect that RepairDB is a function, not a database object, and that ret should be declared as whatever data type is returned by RepairDB.

Posting Permissions

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