violette 0 Junior Poster in Training

Hi. I would like to do insert and update database using data from excel file. before i can insert any data into the db, i have to check whether the field is already in the database or not. the primary key is year_id, period_id and stock_code. IMO, to do data checking, the fields have to be in both place(excel and database). the problem is, the data for year and period in excel file is according to the sheet's name. for example; there are 5 sheets; year, quarter 1, quarter 2, quarter 3, and quarter 4. and the data for each company is arranged according to the sheets. is it possible to compare the sheet name with the field in the database for the checking purposes? if yes, how can i do that? thanks

here's example of my code to do the checking;

Set rs = New ADODB.Recordset
        sqlStr = "SELECT year_id, period_id, stock_code FROM company_financial WHERE stock_code = '" & stockCodeCom & "' "
        rs.Open sqlStr, conn, adOpenStatic

        If rs.EOF Then
            'record not exist in DB
            recordExistCom = False
        Else
            stockCodeCom = rs.Fields("stock_code")
            recordExistCom = True
        End If

        rs.Close
        Set rs = Nothing

note that stockCodeCom is referring to the stock code from the excel file. how can i compare the sheets name with the sql field (year_id and period_id)