Page 2 of 2 FirstFirst 12
Results 16 to 29 of 29
  1. #16
    Kev86 is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Dec 2022
    Posts
    36
    Sorry CJ i am not very tech savvy with all this. So is it this piece of code to use to check whether there is a connection with the sever where the BE is stored?
    Code:
    Function DriveIsAvailable(MDrive As String) As Boolean
    
        On Error Resume Next
    
        ChDir MDrive & ":\"
        DriveIsAvailable = Err = 0
        
    End Function


  2. #17
    Kev86 is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Dec 2022
    Posts
    36
    Sorry CJ just read your code again and now see you have a function then the second part is calling upon that function. So i guess within the code below where you have ":" i will need to put the complete file path?

    Code:
    Function DriveIsAvailable(MDrive As String) As Boolean
    
        On Error Resume Next
    
        ChDir MDrive & ":\"
        DriveIsAvailable = Err = 0
        
    End Function
    Also then in your second piece of code calling that function where you have ("z") i assume i can just put the file name there rather than a Z?

    Really sorry as i say my knowledge on code is basic and i originally built this database a couple of years ago with a lot of help from Google and little knowledge

  3. #18
    Kev86 is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Dec 2022
    Posts
    36
    Sorry CJ just read your code again and now see you have a function then the second part is calling upon that function. So i guess within the code below where you have ":" i will need to put the complete file path?

    Code:
    Function DriveIsAvailable(MDrive As String) As Boolean
    
        On Error Resume Next
    
        ChDir MDrive & ":\"
        DriveIsAvailable = Err = 0
        
    End Function


    Also then in your second piece of code calling that function where you have ("z") i assume i can just put the file name there rather than a Z?

    Really sorry as i say my knowledge on code is basic and i originally built this database a couple of years ago with a lot of help from Google and little knowledge

  4. #19
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    when you link to the BE what is the path?

    It might be something like

    Z:\public\databases\myBE.accdb

    in which case you would just need the Z so you would use

    if DriveIsAvailable("Z") then
    ...
    ...

    if the path is X:\databases\myBE.accdb

    you would just need the X


    if DriveIsAvailable("X") then
    ...
    ...

  5. #20
    Kev86 is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Dec 2022
    Posts
    36
    Hi CJ,

    I use the full file path rather than a drive letter. Also some people might use different letter drives if they have saved a link themselves to the folder location. Can i just use the full file path which is...

    \\maidat01\work\PowerConnect\Projects South\Project Design\CDS\WESTERN\Capital\New Database

  6. #21
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    I’m not at my computer to set up a test environment- only place I’ve needed to use it is with a client who used mapped drives (IT set the mapping so users have no choice) suggest try it and see - experiment for yourself, that way you will gain an understanding of what you are doing.

    Would think you would only need to test for

    \\maidat01\

    so you won’t need the colon ( : ) in the function

  7. #22
    Kev86 is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Dec 2022
    Posts
    36
    Ok thank you, I will have a look and test it.

  8. #23
    Kev86 is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Dec 2022
    Posts
    36
    Hi CJ,

    I have been playing about with the code and it's recognising it's there however every time I test it the message comes up. Even though i have put it on the BeforeUpdate event the job still updates and the message appears saying that the drive could not be reached.

    I had to amend the code as the word DriveIsAvailable it did not like so i just changed that to Drive.

    I now have a module called 'CheckServer' and the code is as follows...

    Code:
    Function Drive(MDrive As String) As Boolean
    
    
        On Error Resume Next
        
        ChDir MDrive & "C:\Users\lock01k\OneDrive - UK Power Networks\Desktop\Database test with Adam"
        Drive = Err = 0
    
    
    End Function
    Then in the BeforeUpdate event linked tot he form i have the following code...

    Code:
    If Drive("C:\Users\lock01k\OneDrive - UK Power Networks\Desktop\Database test with Adam") Then
        'carry on
    Else
       MsgBox "Drive not available, there may be a temporary network failure so please try again later. If the problem persists please contact your IT dept", vbOKOnly
    End If
    I am probably doing something completely wrong but at the moment it's letting me make a change and go to the next line and it's not stopping the update however the message "Drive not available, there may be a temporary network failure so please try again later. If the problem persists please contact your IT dept" is then showing up.

  9. #24
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,938
    Is Drive a reserved word?
    Put the whole path into a string variable and debug.print that. Then copy that and paste into Explorer, does that work?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  10. #25
    Kev86 is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Dec 2022
    Posts
    36
    I changed it to DriveTest and that did the same, not sure if Drive is a reserved word or not. Sorry my knowledge is lacking so i am a little lost of what to do next.

  11. #26
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,938
    Quote Originally Posted by Kev86 View Post
    I changed it to DriveTest and that did the same, not sure if Drive is a reserved word or not. Sorry my knowledge is lacking so i am a little lost of what to do next.
    Start walking your code with F8 and breakpoints then.

    What is Mdrive supposed to be?

    Code:
    ? drivetest( "W")
    False
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  12. #27
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,938
    ? drivetest( "F")
    err is 0
    True

    Code:
    Function DriveTest(MDrive As String) As Boolean
    Dim strPath As String
    
    
    
    
        On Error Resume Next
        strPath = MDrive & ":\Temp"
        ChDir strPath 'MDrive & "\Temp" '"C:\Users\lock01k\OneDrive - UK Power Networks\Desktop\Database test with Adam"
        Debug.Print "err is " & Err
        DriveTest = Err = 0
    
    
    
    
    End Function
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  13. #28
    Kev86 is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Dec 2022
    Posts
    36
    Thank you Welshgasman for your responses however i am still struggling to get it to work. I tried adding your code to a new module but just got an error, when i click Debug the error shows as 'Compile error: Function call on lef-hand side of assignment must return Variant or Object'.


    Code:
    Function DriveTest(MDrive As String) As Boolean
    Dim strPath As String
    
    
    
    
        On Error Resume Next
        strPath = MDrive & ":\Temp"
        ChDir strPath 'MDrive & "\Temp" '"C:\Users\lock01k\OneDrive - UK Power Networks\Desktop\Database test with Adam"
        Debug.Print "err is " & Err
        DriveTest = Err = 0
    
    
    
    
    End Function

  14. #29
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,938
    In the immedfate window enter
    ? drivetest(<WhateverYou MDriveIs>) just like I used my F drive.

    Show EXACTLY how you call it, just as I have done above.

    NB, If you do not have a F:\Temp folder, it is going to return False.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 8
    Last Post: 07-23-2017, 02:04 PM
  2. Record is Deleted
    By Middlemarch in forum Access
    Replies: 3
    Last Post: 07-28-2016, 06:50 AM
  3. Record deleted!!
    By sunnyday in forum Queries
    Replies: 4
    Last Post: 07-08-2015, 07:28 PM
  4. delete query produce #deleted in all deleted values
    By learning_graccess in forum Queries
    Replies: 2
    Last Post: 03-31-2012, 07:20 AM
  5. record deleted
    By akram in forum Access
    Replies: 12
    Last Post: 03-11-2011, 09:23 PM

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