P
PC
Hi all,
I'm use the "NotInList" event to allow users create new records using a
combo box (code below). This part is working fine. My problem is I want the
form to go to the new record after it has been created to allow users enter
the new data. As it stands the users has to close the form and reopen it for
the new Record to become available (note after the execution of this code
the new record appears in the list in the combo box but cannot be selected.
I imagine this is a simple problem but I can't seem to find the answer.
Code follows:
Private Sub cmbTransRef_NotInList(NewData As String, Response As Integer)
Response = acDataErrContinue
If MsgBox("Record " & NewData & " does not exist. Create new Record?",
vbYesNo) = vbYes Then
Dim db As Database
Dim rst As Recordset
Dim sqlTransRef As String
Set db = CurrentDb()
sqlTransRef = "SELECT [tblBankMovementsMain].[TransactionID],
[tblBankMovementsMain].[TransRef] FROM [tblBankMovementsMain]"
Set rst = db.OpenRecordset(sqlTransRef, dbOpenDynaset)
rst.AddNew
rst!TransRef = NewData
rst.Update
Response = acDataErrAdded
rst.Close
End If
Me.Repaint
End Sub
Any advice appreciated
I'm use the "NotInList" event to allow users create new records using a
combo box (code below). This part is working fine. My problem is I want the
form to go to the new record after it has been created to allow users enter
the new data. As it stands the users has to close the form and reopen it for
the new Record to become available (note after the execution of this code
the new record appears in the list in the combo box but cannot be selected.
I imagine this is a simple problem but I can't seem to find the answer.
Code follows:
Private Sub cmbTransRef_NotInList(NewData As String, Response As Integer)
Response = acDataErrContinue
If MsgBox("Record " & NewData & " does not exist. Create new Record?",
vbYesNo) = vbYes Then
Dim db As Database
Dim rst As Recordset
Dim sqlTransRef As String
Set db = CurrentDb()
sqlTransRef = "SELECT [tblBankMovementsMain].[TransactionID],
[tblBankMovementsMain].[TransRef] FROM [tblBankMovementsMain]"
Set rst = db.OpenRecordset(sqlTransRef, dbOpenDynaset)
rst.AddNew
rst!TransRef = NewData
rst.Update
Response = acDataErrAdded
rst.Close
End If
Me.Repaint
End Sub
Any advice appreciated