I wonder if anyone has any idea what could be causing this. Basically all the code below is designed to do is to populate three controls (text boxes) assigned to fields when the user selects a name displayed by the combobox (cboConsumer) which it does BUT---
If the user begins typing a name and it appears anywhere in the combobox display list by clicking the mouse on it the controls are populated and the user is returned to the form to continue filling it out. However, if the user begins typing enough of a name so that the correct name is highlighted and the selection process is completed by pressing the ENTER key instead, the controls get populated as before BUT the user is returned to a new record instead and so they have to navigate back to the previous record to finish completing it. (The original version of this code which behaved the same was even simpler in that the textboxes were populated directly. The variables were only added to aid in debugging the issue.
A couple of related points of interest are that when a break point was set on the "Exit Sub" line and the form checked before executing that line the relevant controls were populated correctly and the form was still displaying the correct record. Also if the three lines of code that assign values to the textboxes were commented out the code returned the form to the current record regardless whether Click or Enter was used to select from the combobox.
I can't imagine how the means of selecting an entry from the combobox (mouse click or Enter key) would trigger a new record being created (or not) but somehow it is.
**************************************
Private Sub cboConsumer_Click()
On Error GoTo cboConsumer_Click_Error
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim lngCId As Long
Dim strPlna As String
Dim strApt As String
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("Qry_LU_Consumer_NewEntry", dbOpenDynaset)
If Not (rst.EOF And rst.BOF) Then 'rst is not empty
rst.FindFirst "[CId] =" & Me.cboConsumer
lngCId = rst("CId").Value
strPlna = rst("plna").Value
strApt = rst("Apt").Value[/indent]
If rst.NoMatch Then
'Nothing to do
End If
Else
'no records = no match = should never happen
End If
rst.Close
Set rst = Nothing
Set dbs = Nothing
Me.txtCId.Value = lngCId
Me.txtplna.Value = strPlna
Me.txtApt = strApt
Me.cboConsumer.Value = Null
On Error GoTo 0
Exit Sub
cboConsumer_Click_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure cboConsumer_Click of VBA Document Form_Master_Consumer_New_Entry"
End Sub
If the user begins typing a name and it appears anywhere in the combobox display list by clicking the mouse on it the controls are populated and the user is returned to the form to continue filling it out. However, if the user begins typing enough of a name so that the correct name is highlighted and the selection process is completed by pressing the ENTER key instead, the controls get populated as before BUT the user is returned to a new record instead and so they have to navigate back to the previous record to finish completing it. (The original version of this code which behaved the same was even simpler in that the textboxes were populated directly. The variables were only added to aid in debugging the issue.
A couple of related points of interest are that when a break point was set on the "Exit Sub" line and the form checked before executing that line the relevant controls were populated correctly and the form was still displaying the correct record. Also if the three lines of code that assign values to the textboxes were commented out the code returned the form to the current record regardless whether Click or Enter was used to select from the combobox.
I can't imagine how the means of selecting an entry from the combobox (mouse click or Enter key) would trigger a new record being created (or not) but somehow it is.
**************************************
Private Sub cboConsumer_Click()
On Error GoTo cboConsumer_Click_Error
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim lngCId As Long
Dim strPlna As String
Dim strApt As String
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("Qry_LU_Consumer_NewEntry", dbOpenDynaset)
If Not (rst.EOF And rst.BOF) Then 'rst is not empty
rst.FindFirst "[CId] =" & Me.cboConsumer
lngCId = rst("CId").Value
strPlna = rst("plna").Value
strApt = rst("Apt").Value[/indent]
If rst.NoMatch Then
'Nothing to do
End If
Else
'no records = no match = should never happen
End If
rst.Close
Set rst = Nothing
Set dbs = Nothing
Me.txtCId.Value = lngCId
Me.txtplna.Value = strPlna
Me.txtApt = strApt
Me.cboConsumer.Value = Null
On Error GoTo 0
Exit Sub
cboConsumer_Click_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure cboConsumer_Click of VBA Document Form_Master_Consumer_New_Entry"
End Sub