Extract data from a database file

  • Dear Team,


    I have a database file that has whole data @attached from that data I simply want an output for that I have discovered a match function that is presently functioning with the same activesheet to extract it but I want to utilise it from the saved database





    Please assist.

  • Go to Best Answer
  • You cannot use SQL on a CSV file.


    You need to open the CSV file in Excel then use your code or formula to extract the desired data.

    We now have a reputation system in place. If my reply helped please "Like" the reply by clicking the "Like" icon at bottom right of my reply.

  • You can use SQL on a text file. I don't understand why the OP opens a recordset, populates it, then replaces it with a new blank recordset, and finally tries to use a recordset as a worksheet.

    Rory
    Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: nothing works and they don’t know why

  • Mr. Rory,

    Thanks for your response.

    I had created a database sheet in the same file as "database" which is being used to run the function, and it was working fine, but instead of copying and pasting the data again and again, there is a real database saved on the server that is regularly updated, so I wanted to use that server data directly in the function so that each time will have the updated records.

    Here is the current backup code that I use to acquire the most recent and fresh data.

    Instead, I expected to have a direct access to the server's CSV file for the function.



    Thank you very much.

  • There doesn't seem to be a question in there anywhere. What exactly is your problem currently?

    Rory
    Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: nothing works and they don’t know why

  • Dear Rory,


    Sorry about that - could not well describe it

    In the next line, I intend to link the data of the recordset so that when I run the function or utilise it, it will execute with the most recent version straight from the server database.


    Set rs = newADODB.Recordset
    With rs ''Getting error here now


    Instead of utilising the sub "GetDataFromSource," I'd want to link it in the preceding line.


    #attached the file for your ref


  • Sorry, but I am not following. Your code (from post 3 which is the only place you have those lines) makes no sense to me since you populate the recordset with data from the CSV and then immediately destroy and recreate the recordset with a second Set rs = New ADODB.Recordset line. Why do you do that?

    Rory
    Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: nothing works and they don’t know why

  • Oh, I get your viewpoint here; since it has already been made, there is no need for a new one, right?

    Could you kindly connect that sub () here to the function? and complete it please??


    With rs


    Thanks very much

  • I still have no idea what you mean. Your function already creates and populates the recordset. What does the sub have to do with anything?

    Rory
    Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: nothing works and they don’t know why

  • SUB () has been created to get the data from sharedrive to a local excel file - and then the function executes the most recent/updated value

    I have to run SUB() each time for most recent/updated data-

    so I want that sub() should connect in that function ( with RS) so that it will directly link to sharedriver rather than local data


    • Best Answer

    Your function doesn't need that sub. As I said earlier, you have already extracted the data from the server into a recordset. It's not clear what you're trying to do with the returned data, but I suspect you should be adding a WHERE clause to your SQL to restrict the data returned based on the function parameters.

    Rory
    Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: nothing works and they don’t know why

  • Finally resolved- this is all I wanted.
    Thanks for your support


    I need some last advice on how to get the red font. If there are no matching records, "Not Found" should appear in red font.


    ClientMatch = "Not Found"

    ClientMatch.Interior.Color = vbRed

  • Rmrekoj

    Selected a post as the best answer.
  • You cannot set the font colour from a UDF used in a cell.

    Rory
    Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: nothing works and they don’t know why

  • Use conditional formatting

    We now have a reputation system in place. If my reply helped please "Like" the reply by clicking the "Like" icon at bottom right of my reply.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!