Gasman
Enthusiastic Amateur
- Local time
- Today, 09:06
- Joined
- Sep 21, 2011
- Messages
- 17,057
Hi everyone,
When does a Lost Focus Event not fire please?
I ask as I have a form for crewnames. It consists of two text controls, surname and initials.
The lost focus for the surname makes the text Proper.
The lost focus for the initials makes the text uppercase.
In my links form I have the Not in List event open the crewnames form and put the value entered in the links form in the surname field (This code was supplied by a member here, and has saved me a lot of time keying in missing data)
However, when I tab out and go to the initials control, the code does not fire?
I enter the initials and tab out, and that code always fires, so I have to click back into the surname control and tab out again?
When does a Lost Focus Event not fire please?
I ask as I have a form for crewnames. It consists of two text controls, surname and initials.
The lost focus for the surname makes the text Proper.
The lost focus for the initials makes the text uppercase.
In my links form I have the Not in List event open the crewnames form and put the value entered in the links form in the surname field (This code was supplied by a member here, and has saved me a lot of time keying in missing data)
However, when I tab out and go to the initials control, the code does not fire?
I enter the initials and tab out, and that code always fires, so I have to click back into the surname control and tab out again?
Code:
Private Sub Crew_ID_NotInList(NewData As String, Response As Integer)
Response = AddNewToList(NewData, "Crew", "Surname", "Crews", "frmCrew")
End Sub
Code:
' usage..... Response = AddNewToList(NewData, "LtblCounties", "txtCounty", "Counties")
Public Function AddNewToList(NewData As String, stTable As String, _
stFieldName As String, strPlural As String, _
Optional strNewForm As String) As Integer
On Error GoTo err_proc
'Adds a new record to a drop down box list
'If form name passed, then open this form to the newly created record
'Declare variables
Dim rst As DAO.Recordset
Dim IntNewID As Long
Dim strPKField As String
Dim strMessage As String
' Display message box asking if user wants to add the new item
strMessage = "'" & NewData & "' is not in the current list. " & Chr(13) & Chr(13) & _
"Do you want to add it to the list of " & strPlural & "?" & Chr(13) & Chr(13) & _
"(Please check the entry before proceeding)."
If MsgBox(strMessage, vbYesNo + vbQuestion + vbDefaultButton2, "Add New Data") = vbYes Then
Set rst = CurrentDb.OpenRecordset(stTable, , dbAppendOnly)
rst.AddNew
rst(stFieldName) = NewData 'Add new data from combo box
strPKField = rst(0).Name 'Find name of Primary Key (ID) Field
rst.Update
rst.Move 0, rst.LastModified
IntNewID = rst(strPKField)
'if a form specified, then open the form with the primary key equal to the new record ID as the criteria
If strNewForm <> "" Then DoCmd.OpenForm strNewForm, , , strPKField & "=" & IntNewID
AddNewToList = acDataErrAdded 'Set response 'Data added'
Else
AddNewToList = acDataErrContinue 'Set response 'Data NOT added'
End If
exit_proc:
On Error Resume Next
rst.Close
Set rst = Nothing
Exit Function
err_proc:
MsgBox "Error in Function: 'AddNewToList'" & Chr(13) & Err.Description, , "Function Error"
Resume exit_proc
End Function