Results 1 to 9 of 9
  1. #1
    Starter-4-10 is offline Novice
    Windows 10 Access 2003
    Join Date
    Dec 2016
    Posts
    27

    Edit startup code after moving database to Windows 10/Ac 2003. Novice, grateful for any advice.

    The database ran fine with XP/Access 2002, iffy with Windows 10/Access 2003. References look ok. All the main objects remain at the same C:/… addresses. As far as possible, I’d like Access to look for anything it wants, in the same folder as the front and back ends and the photo folders.

    Autoexec says RunCode (GetDBPath() pasted below) and then OpenForm (frmMainMenu). MsgBox “There is no object in this control” occurs twice before frmMainMenu opens. It looks normal, but the photo-linked-to-record display doesn’t work properly. The tables look fine.

    Option Compare Database
    Option Explicit

    Public strDBPath As String
    Public strPhotoDir1 As String
    Public strPhotoDir2 As String
    Public strPhotoDir3 As String
    Public strPhotoDir4 As String 'line added DB
    Public strGraphicDir As String

    Public intFormHeight As Integer
    Public intFormWidth As Integer

    Function GetDBPath()

    Dim MyDB As Database
    Dim intTitleLength, intDBLength, intCount As Integer

    Set MyDB = CurrentDb() 'MyDB now means "this database"

    intDBLength = Len(MyDB.Name)

    For intCount = intDBLength To 1 Step -1
    If Mid(MyDB.Name, intCount, 1) = "" Then
    Exit For
    End If
    Next

    intTitleLength = intDBLength - intCount



    strDBPath = Left(MyDB.Name, Len(MyDB.Name) - intTitleLength)
    strPhotoDir1 = strDBPath & "dbase photos1"
    strPhotoDir2 = strDBPath & "dbase photos2"
    strPhotoDir3 = strDBPath & "dbase photos3"
    strPhotoDir4 = strDBPath & "dbase photos4" ' line added DB
    strGraphicDir = strDBPath & "dbase graphics"
    'MsgBox "Autogenerated paths:@Database: " & strDBPath & "@Photos: " & strPhotoDir4

    Debug.Print "Exit Basinitialise" 'Tracking DB

    End Function

    btw ... if there's anything annoying about this post (Not here! Too long! Why didn't you ...!) please say so.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    Code:
    Function GetDBPath()
    
    dim sFilePath
    dim vDir
    dim i as integer
    
    sFilePath = currentdb.Name 
    i = InStrRev(sFilePath, "\")
    If i > 0 Then vDir = Left(sFilePath, i)
    
    strPhotoDir1 = strDBPath & "dbase photos1"
    strPhotoDir2 = strDBPath & "dbase photos2"
    strPhotoDir3 = strDBPath & "dbase photos3"
    strPhotoDir4 = strDBPath & "dbase photos4" ' line added DB
    strGraphicDir = strDBPath & "dbase graphics"
    'MsgBox "Autogenerated paths:@Database: " & strDBPath & "@Photos: " & strPhotoDir4
    
    Debug.Print "Exit Basinitialise" 'Tracking DB
    
    'GetDBPath = vDir
    End Function
    the above will get the current db directory and assign all the sub folder paths.
    if this fails before the form opens, then something else is failing. Try debuging and locate the exact cause.

  3. #3
    Starter-4-10 is offline Novice
    Windows 10 Access 2003
    Join Date
    Dec 2016
    Posts
    27
    Thanks for your skilled help. Your code may help later, when trying to get everything into one folder, but at present it doesn't change the crippled performance after frmMainMenu opens.

  4. #4
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Is your error in the code above or in frmMainMenu? Maybe there are controls on your form which are invalid in some way - by what you are seeing photo display is one of them. Go into design view of the main form and look thru the objects.

  5. #5
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    If you use a line like
    Code:
    Dim MyDB As Database
    you should specify what type of database "DAO" or "ADO"
    So you would have
    Code:
    Dim MyDB As DAO.Database
    --------------
    If you create an object using syntax like
    Code:
    Set MyDB = CurrentDb()
    be sure to destroy the object before the sub/function ends:
    Code:
    Set MyDB = Nothing
    --------------
    You must explicitly declare variables.
    Code:
    Dim intTitleLength, intDBLength, intCount As Integer
    Here "intTitleLength" and "intDBLength" are declared as variants and only "intCount" is declared as an Integer.
    You should use
    Code:
    Dim intTitleLength As Integer, intDBLength As Integer, intCount As Integer

  6. #6
    Starter-4-10 is offline Novice
    Windows 10 Access 2003
    Join Date
    Dec 2016
    Posts
    27
    Thanks, aytee111 and ssanfu - useful ideas.

    The code in my question was written ~2000. At Startup, what works fine in XP crashes on the Mid of If Mid(MyDB.Name - Can't find project or library. In References, unchecking Mic Off XP Web Components solves that (but long address in References window that a) doesn't exist in Windows 10 and b) runs out of space, so can't see what's missing - maybe OWC10.dll v2? Browse goes to System 32.

    Close database, open with Shift, highlight frmMainMenu, click Design Icon - and get 'There is no object in this control' - twice. Looks like
    aytee111's right about that.

    ssanfu/Steve's code-writing advice - HTH? Yes indeed - pitched at my level, and I'll do some editing. But first, some desperate experiments with compact/repair/compile ...






  7. #7
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Steve has hit on some of my pet peeves for sure. A couple of observations I might add are
    -being explicit about the type library means you must have set a reference to it. Changing the code to suit this recommended practice can actually cause a compile error if the needed library reference has not been set.
    - You must explicitly declare variables. OK, being nit-picky here perhaps, but the variables are explicitly declared, otherwise there would be a compile error due to the Option Explicit parameter, which should always be set. I know that what is meant is that the variable type must be declared for each in a multi-line declaration, otherwise the default is the Variant data type.
    - I have to wonder if some code change was made because I don't see how this can work in any version
    strPhotoDir1 = strDBPath & "dbase photos1"
    From what I think I know about the path string, it would not contain the ending slash, and you're appending what looks like a folder reference to it. So I see it as becoming like
    C:\MyDatabases\Database1dbase photos1 not C:\MyDatabases\Database1\dbase photos1. That brings up one more pet peeve: NEVER any spaces or special characters in folder names or files. Just sayin....
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  8. #8
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    @Micron
    I did "clean up" the code, always have "Option Explicit" in my dBs and executed the code. It worked, not that I know the purpose...
    I totally agree about the spaces in folder names.

    From what I think I know about the path string, it would not contain the ending slash
    I also wondered about this. If you use "Currentdb.Name", you get path and filename of the dB. Deleting the dB name leaves the path with an ending slash. I had to test it to confirm.

    If you are interested, here is the code I used to test:
    Code:
    Option Compare Database
    Option Explicit
    
    Public strDBPath As String
    Public strPhotoDir1 As String
    Public strPhotoDir2 As String
    Public strPhotoDir3 As String
    Public strPhotoDir4 As String    'line added DB
    Public strGraphicDir As String
    
    Public intFormHeight As Integer
    Public intFormWidth As Integer
    
    Sub GetDBPath()
        Dim intCount As Integer
    
        strDBPath = CurrentDb.Name
        intCount = InStrRev(strDBPath, "\")
    
        strDBPath = Left(strDBPath, intCount)
        strPhotoDir1 = strDBPath & "dbase photos1"
        strPhotoDir2 = strDBPath & "dbase photos2"
        strPhotoDir3 = strDBPath & "dbase photos3"
        strPhotoDir4 = strDBPath & "dbase photos4"    ' line added DB
        strGraphicDir = strDBPath & "dbase graphics"
        MsgBox "Autogenerated paths:" & vbNewLine & "@Database: " & strDBPath & vbNewLine & "@Photos:     " & strPhotoDir4
    
        '    Debug.Print "Exit Basinitialise"    'Tracking DB
    
    End Sub
    I also changed it from a Function to a Sub.....

  9. #9
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Deleting the dB name leaves the path with an ending slash.
    I missed the part where you were doing that in your original post, although I do see it in your follow up code.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 14
    Last Post: 12-30-2015, 09:42 AM
  2. Replies: 3
    Last Post: 12-15-2014, 03:28 AM
  3. Replies: 3
    Last Post: 11-13-2014, 07:25 PM
  4. Replies: 3
    Last Post: 02-22-2013, 04:23 PM
  5. Problem with Access 2003 database after moving PCs
    By ValiantSaint in forum Access
    Replies: 2
    Last Post: 06-25-2010, 01:55 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums