Public Function InsertMachineHoursRecord() As Boolean Dim SaveTime As Date Dim db As DAO.Database Dim rs As DAO.

Recordset '//Variables used to hold field values Dim strEmployee = Me.cboEmployee.Value Dim dtmEventDate = Me.txtDate.Value Dim lngEventTypeID = Me.cboType.Value Dim dtmStartTime = me.txtStartTime.Value Dim dtmEndTime = me.txtEndTime.Value Dim strMachineNumber = Me.txtMachine.Value Dim strDescription = Me.txtDescription.Value '//Database Location Const DB_LOCATION = "C:\SomeFolder\SomeDatabase.mdb" '//If errors occur the function will exit with a return value of false (insertion failed) On Error GoTo ErrHandler: '//Get Field Values from Form and store in variables strEmployee = Me.cboEmployee.Value dtmEventDate = Me.txtDate.Value lngEventTypeID = Me.cboType.Value dtmStartTime = Me.txtStartTime.Value dtmEndTime = Me.txtEndTime.Value strMachineNumber = Me.txtMachine.Value strDescription = Me.txtDescription.Value '//Recommended: Validate all values here before inserting into DB '// -- Check that data is of right type and meets business rules '//Table has a datecreated/datemodified timestamp for each record SaveTime = Now '//Open Database If db Is Nothing Then Set db = DAO.Workspaces(0).OpenDatabase(DB_LOCATION) End If '//Open Table If rs Is Nothing Then Set rs = db.OpenRecordset("MachineRepairHours", dbOpenDynaset) End If '//Create a new record With rs .AddNew ![Employee] = strEmployee ![EventDate] = dtmEventDate ![EventTypeID] = lngEventTypeID ![StartTime] = dtmStartTime ![StopTime] = dtmStopTime ![HoursWorked] = ((dtmStopTime - dtmStartTime) * 24) ![MachineNumber] = strMachineNumber ![DateModified] = SaveTime ![Description] = strDescription '//Insert Record into Database .Update InsertMachineHoursRecord = True '//SUCCESSFUL INSERTION

8 or later Object Library 'via the Tool | References.Seek Range("CaseNum").Open stCon ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''' 'Find and Update the record in Access With rst .CursorLocation = adUseServer .Index = "PrimaryKey" .12. stCon = "Provider=Microsoft.Open "tbl_QuoteLog". Persist Security Info = False.Value .Close Set rs = Nothing db. 3.0. adCmdTableDirect .Connection Dim rst As ADODB. Value2). Set cnt = New ADODB.EOF Then .Value If Not rst.OLEDB. cnt.Recordset Dim stDB As String Dim stCon As String 'Instantiate the ADO COM's objects. Field2) VALUES (Value1.Description Resume My_Exit End Sub Sub LogOut() 'Add a reference to the Microsoft ActiveX Data 2.Connection Set rst = New ADODB.Fields("UndWrite") = Sheets("LogOut"). 1.End With '//Note that we use recordset in this example..mdb" 'Create the connectionstring. in the VB-editor Dim cnt As ADODB.. '//Make sure we have closed the database My_Exit: rs." & _ "Data Source=" & stDB & ". but equally effective '// is to create an update query command text and simply run the update query: '// (INSERT INTO Table (Field1.Close Set db = Nothing Exit Function ErrHandler: MsgBox Err.Ace.Range("b9")." 'Open the connection cnt.Recordset 'Pathway and name of the database stDB = "T:\Trad\Data\db_StopLoss.

Close cnt.Update Else MsgBox "Log Out Failed" End If End With ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''' 'Close the recordset and close the connection.Range("k2") = "p" Then . rst.Fields("Status") = Sheets("LogOut").Range("b14").Fields("QtDeadDt") = Sheets("LogOut").Close Set cnt = Nothing Set rst = Nothing End Sub .Range("b11").Value .Range("b12").Range("b13").Value If Sheets("LogOut").Fields("EmpNum") = Sheets("LogOut").Value .Fields("SpecDed") = Sheets("LogOut").Value End If ..