Hi, I have some code in a spreadsheet on the before close event that asks the user with a vbyes/no msgbox if they would like to update the master database. If they select yes then I run a routine to take data from the worksheet and append a new record into my database. If they select no then I exit the sub and just close the worksheet.
What I would like to do is check the database to make sure I am not creating a duplicate record before I run the update. Here is the code I use to update the database:
Thanks for any help you all can provide. This site has been a life saver!
KT
What I would like to do is check the database to make sure I am not creating a duplicate record before I run the update. Here is the code I use to update the database:
Code:
Sub UpdateMasterDb()
Dim cn As ADODB.Connection, rs As ADODB.Recordset
Dim intResale As Integer
Dim intHours As Integer
intHours = Worksheets("Project pricing summary").Range("G60").Value + Worksheets("Project pricing summary").Range("G61").Value _
+ Worksheets("Project pricing summary").Range("G62").Value
intResale = Worksheets("Project information").Range("D26").Value + Worksheets("Project information").Range("D28").Value
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=T:\Quot\CONTROLS\Formulas\Estworksheet\Master Quote List\Controls Estimating Database.mdb;"
Set rs = New ADODB.Recordset
rs.Open "tblMasterQuoteList", cn, adOpenKeyset, adLockOptimistic, adCmdTable
rs.AddNew
rs.Fields("Project") = Worksheets("Project information").Range("L6").Value
rs.Fields("Customer") = Worksheets("Project information").Range("D6").Value
rs.Fields("Location") = Worksheets("Project information").Range("D7").Value
rs.Fields("Quote_Type") = Worksheets("Project information").Range("L7").Value
rs.Fields("Estimator") = Worksheets("Project information").Range("D8").Value
rs.Fields("Date_Quoted") = Worksheets("Project information").Range("L5").Value
rs.Fields("Comments_Scope") = Worksheets("Project pricing summary").Range("C15").Value
rs.Fields("File_Path_Hyperlink") = Application.ActiveWorkbook.FullName
rs.Fields("Resale") = intResale
rs.Fields("Hardware") = Worksheets("Project information").Range("D27").Value
rs.Fields("Eng_Hours") = intHours
rs.Fields("Travel") = Worksheets("Project pricing summary").Range("L59").Value
rs.Update
MsgBox ("Database has been updated")
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
End Sub
KT