Hi Jay
You should be able to incorporate this module as
necessary.
Geoff
Option Explicit
' Assumes Reference to Microsoft DAO Object Library
' (On Tools menu, References).
' Declare variables at top of module:
Dim mobjRS As DAO.Recordset
Dim Name As String
Dim Address1 As String
Dim Address2 As String
Dim City As String
Dim State As String
Dim Zip As String
Dim LogDate As Date
Dim LogTime As Date
Sub TestWriteDataToDatabase()
' YOU ASSIGN VALUES TO VARIABLES HERE
' (FROM COMBO/TEXTBOXES):
Name = "Jay"
Address1 = "JaysAddress1"
Address2 = ""
City = "JaysCity"
State = "JaysState"
Zip = "JaysZip"
LogDate = #9/16/03#
LogTime = #5:00:00 PM#
' CALL NEXT PROCEDURE TO WRITE DATA:
WriteDataToDatabase
End Sub
Sub WriteDataToDatabase()
Const strDBPathName As String = "c:\logfiles\worklog.mdb"
Const strDBTableName As String = "DailyWork"
Dim objDB As DAO.Database
On Error GoTo ErrorHandler
Set objDB = OpenDatabase(strDBPathName)
Set mobjRS = objDB.OpenRecordset(strDBTableName)
With mobjRS
.AddNew
' Call the next subprocedure (WriteTextField),
' passing fieldnames and values to subprocedure:
WriteTextField "Name", Name
WriteTextField "Address1", Address1
WriteTextField "Address2", Address2
WriteTextField "City", City
WriteTextField "State", State
WriteTextField "Zip", Zip
.Fields("LogDate") = LogDate
.Fields("LogTime") = LogTime
.Update
End With
Bye:
If Not mobjRS Is Nothing Then mobjRS.Close
Set mobjRS = Nothing
If Not objDB Is Nothing Then objDB.Close
Set objDB = Nothing
Exit Sub
ErrorHandler:
MsgBox Err.Description, vbOKOnly, "Error No: " & Err.Number
Resume Bye
End Sub
Private Sub WriteTextField( _
strFieldName As String, _
vntValue As Variant)
' This subprocedure ensures we don't write
' empty strings to the Text fields:
If vntValue <> vbNullString Then
mobjRS.Fields(strFieldName) = vntValue
End If
End Sub