Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2008

    Unanswered: entry form adds blank record?

    I created an entry form with 2 bound fields and 3 unbound fields.

    (form recordSource Transactions table)
    Date - bound
    SSN - unbound combobox (row source employee table)
    Activity - unbound combobox (row source activity table)
    Location - unbound combox (row source location table)
    Hours - bound

    After user tabs through Hour field, the infomation should be added to transaction table. The data is added to the transaction table. But when user exits from the form a blank record is also added. what i am doing wrong?

    Private Sub txtHours_LostFocus()

    Dim Db As DAO.Database
    Dim Rs As DAO.Recordset
    Dim dtDate As Date
    Dim strSSN As String
    Dim strActivity As String
    Dim strLocation As String
    Dim sngHours As Single
    Dim ctl As Object

    dtDate = txtDate
    strSSN = cboSSN
    strActivity = cboActivity
    strLocation = cboLocation
    sngHours = txtHours

    Set Db = CurrentDb
    Set Rs = Db.OpenRecordset("Transactions", dbOpenDynaset)

    Rs!TransactionDate = dtDate
    Rs!TransactionSSN = strSSN
    Rs!TransactionActivity = strActivity
    Rs!TransactionLocation = strLocation
    Rs!TransactionHours = sngHours

    Rs.Bookmark = Rs.LastModified

    'clear unbound controls

    For Each ctl In Me.Controls
    Select Case ctl.ControlType
    Case acTextBox, acComboBox
    If Len(ctl.ControlSource) = 0 Then
    ctl.Value = Null
    End If
    Case Else
    End Select

    'clear bound controls
    txtDate.Value = ""
    txtHours.Value = ""

    End Sub

  2. #2
    Join Date
    May 2005
    Nevada, USA
    Provided Answers: 6
    Typically you either want to use a form bound to the table or use code to add the data, not both. My guess is the bound form is adding the record.

Posting Permissions

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