Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2012

    Unanswered: Qualify data before writing to recordset

    Need a way to mandate that the date be filled in. I am new to unbound forms writing to a recordset. But the is what I have come up with so far.

    Private Sub btnSaveRecord_Click()
    ' make sure date is filled out

    ' open connection and recordset
    Dim cnConnection As ADODB.Connection
    Set cnConnection = New ADODB.Connection
    Dim strConnection As String
    strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & CurrentProject.Path & "\metrix_front.mdb;"
    cnConnection.Open strConnection
    Dim rsRecordset As ADODB.Recordset
    Set rsRecordset = New ADODB.Recordset
    rsRecordset.CursorType = adOpenDynamic
    rsRecordset.LockType = adLockPessimistic
    rsRecordset.Open "SELECT * FROM tblDailyPlan", cnConnection
    'write the new record data to table
    rsRecordset!ActivityDate = txtActivityDate
    rsRecordset!ShipClass_ID = txtShipClass
    rsRecordset!Activities_ID = txtActivity
    rsRecordset!Inputs = txtInputs
    rsRecordset!CompletedAct = txtCompletedActions
    rsRecordset!ActualTime = txtActualTime
    rsRecordset!Comments = txtComments
    rsRecordset!Employee_ID = [Forms]![frmLogonAssist]![Employee_ID]
    'clear form and close connections
    Dim ctl As Control
    On Error Resume Next
    For Each ctl In Me.Controls
    ctl.Value = Null
    Next ctl
    txtInputs.Enabled = True 'reactivates control in case "Admin" or "Leave" was selected
    txtCompletedActions.Enabled = True 'reactivates control in case "Admin" or "Leave" was selected
    ' dont like this but it works most of the time - delay is so that recordset can be successfully writen to table before requery runs
    TWait = Time
    TWait = DateAdd("s", 3, TWait)
    Do Until TNow >= TWait
    TNow = Time
    End Sub

  2. #2
    Join Date
    Apr 2012
    Private Sub btnSaveRecord_Click()
    ' make sure date is filled out

    If Nz(txtActivityDate,"")="" Then
    MsgBox "Enter date."
    Exit Sub
    End If

    ' open connection and recordset

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts