+ Reply to Thread
Results 1 to 3 of 3

Pro Tips Or Advise Needed Concerning A Code A Found On YouTube - Multiple Users Editing

Hybrid View

  1. #1
    Registered User
    Join Date
    09-23-2019
    Location
    Ghana
    MS-Off Ver
    2016 32 bit and 64 bit
    Posts
    92

    Pro Tips Or Advise Needed Concerning A Code A Found On YouTube - Multiple Users Editing

    Cross posted at:
    https://www.mrexcel.com/board/member...y-mort.401365/
    The reason is that it has been up there for a few days now and I can't get solution for it.

    The variables
    Option Explicit
    Dim objFSO, objFile As Object
    Dim objConnection, objRecordset As Object
    Dim LastLocalChange, LastDbUpdate As Date
    Dim DbFile, ConnString As String
    This part of the code sync to the database:
    Sub SyncToDatabase()
        DbFile = Sheet1.Range("M5").Value 'Customer Database Location
        LastLocalChange = Sheet1.Range("B12").Value
        Set objFSO = CreateObject("Scripting.FileSystemObject")
        On Error GoTo FileMissing
        Set objFile = objFSO.GetFile(DbFile)
        If objFile.DateLastModified < LastLocalChange Then 'Local Change was made, update Database
            Kill (DbFile) 'Delete the current database version
            ThisWorkbook.Sheets("CustDb").Copy
            ActiveWorkbook.SaveAs DbFile, FileFormat:=51
            ActiveWorkbook.Close False
        End If
        Exit Sub
    FileMissing:
        MsgBox "Please browse for the database file", vbInformation, "SlimSoft Systems"
        BrowseForFile
    End Sub
    This part of the code sync from the database:
    Sub SyncFromDatabase()
        LastLocalChange = Sheet1.Range("B12").Value
        DbFile = Sheet1.Range("M5").Value 'Customer Database Location
        Set objFSO = CreateObject("Scripting.FileSystemObject")
        On Error GoTo FileMissing
        Set objFile = objFSO.GetFile(DbFile)
        If objFile.DateLastModified > LastLocalChange Then 'Database Change was made, update Local Database
            'Check Last Database Update
            Sheet2.Range("A2:G9999").ClearContents 'Clear existing data
            On Error Resume Next
            Set objConnection = CreateObject("ADODB.Connection")
            Set objRecordset = CreateObject("ADODB.Recordset")
            objConnection.Open "Provider=Microsoft.ACE.OLEDB.12.0;" & "Data Source=" & _
            Sheet1.Range("M5").Value & ";Extended Properties=""Excel 12.0 Xml;HDR=Yes;IMEX=0"";"
            objRecordset.Open "Select * FROM [CustDb$]", objConnection
            
            Sheet2.Range("A2").CopyFromRecordset objRecordset
            
            objRecordset.Close
            objConnection.Close
            On Error GoTo 0
        End If
        Exit Sub
    FileMissing:
        MsgBox "Please browse for the database file", vbInformation, "SlimSoft Systems"
        BrowseForFile
    End Sub
    I still need help with this please

    So I tried to run a few tests and what I saw was that when I added new sheets to the custData workbook and sync the data to the database, all the sheets are deleted and a new sheet named CustDb is created.

    Is there a way I can, maybe delete only the CustDb sheet, update it with the new data and leave the other sheets undeleted?

    Thanks for helping me out.

  2. #2
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Pro Tips Or Advise Needed Concerning A Code A Found On YouTube - Multiple Users Editin

    i didn't read all of your code. but this:
    Quote Originally Posted by Kelly mort View Post

    Is there a way I can, maybe delete only the CustDb sheet, update it with the new data and leave the other sheets undeleted?
    .
    does have an answer. select the custDB sheet, delete it and then do whatever you want with your data. your quote really doesn't make sense. it sounds like you want to update something, some sheet. then you wanna del the custDB sheet. and not del all the rest of the sheets. don't know about some of your other talk, but del'ing a sheet is easy:
    sheets("sheet name here").delete
    don't forget to turn off the alerts before.

  3. #3
    Registered User
    Join Date
    09-23-2019
    Location
    Ghana
    MS-Off Ver
    2016 32 bit and 64 bit
    Posts
    92

    Re: Pro Tips Or Advise Needed Concerning A Code A Found On YouTube - Multiple Users Editin

    Thanks for the help.
    I wish all my requests could be addressed.

    The current code is aimed at dealing with a single sheet from the database and a specific sheet from the user's workbook.

    And now, I want a way to handle multiple sheets from the database and also target multiple sheets from the user's workbook.
    Last edited by AliGW; 12-11-2020 at 06:06 AM. Reason: PLEASE don't quote unnecessarily!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Multiple Users Editing File Concurrently
    By ormsbyd9 in forum Excel General
    Replies: 7
    Last Post: 08-06-2020, 12:52 AM
  2. Tips to elliminate data entry errors from multiple users
    By Sjordan1307 in forum Excel General
    Replies: 1
    Last Post: 09-19-2019, 12:36 PM
  3. Replies: 2
    Last Post: 10-22-2016, 05:04 PM
  4. Multiple Users editing workbook at same time
    By amymsellers in forum Excel General
    Replies: 2
    Last Post: 06-07-2016, 08:39 AM
  5. [SOLVED] Password code designed for 5 Users - NAVIGATION Help Needed! - CODE Issue!
    By JJFletcher in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 11-09-2014, 10:46 AM
  6. Replies: 5
    Last Post: 05-22-2012, 04:14 PM
  7. Found Code to List All Folders and Size in Certain Directory. Need Help Editing.
    By jcranst in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-09-2012, 03:11 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1