Mr_Adams
Active Member
- Joined
- Oct 7, 2002
- Messages
- 475
I use the folloing code to add a new record to a table if no record exist. Then the form used for entry into the table should open on that record so the user can complete all required fileds. But right now the form opens up with record number 1
Is there a way to use Filter with along with the "DoCmd.OpenForm "Department Maintenance"" and the "NewData" (from code below) so that the new record opens?
If not could someone show me how I can accomplish this?
Here is the code
Is there a way to use Filter with along with the "DoCmd.OpenForm "Department Maintenance"" and the "NewData" (from code below) so that the new record opens?
If not could someone show me how I can accomplish this?
Here is the code
Code:
Private Sub DEPARTMENT_NotInList(NewData As String, Response As Integer)
' Add a new category by typing a name in Department combobox.
Dim intNewDepartment As Integer, strTitle As String, intMsgDialog As Integer
Dim strMsg As String, rst As Recordset, Db As Database, newRst As Recordset
Dim DepartmentID As Long
' Display message box asking if user wants to add a new Department category.
strTitle = "New Department"
strMsg = "'" & NewData & "' is not in the Department list. "
strMsg = strMsg & "Would you like to add it?"
intMsgDialog = vbYesNo + vbQuestion + vbDefaultButton1
intNewDepartment = MsgBox(strMsg, intMsgDialog, strTitle)
If intNewDepartment = vbNo Then
Response = acDataErrDisplay
Else
Set Db = CurrentDb()
Set rst = Db.OpenRecordset("Departments")
rst.AddNew
rst![Department Name] = NewData
rst.Update
Response = acDataErrAdded
rst.Close
'Open the Department Maintenance form
DoCmd.OpenForm "Department Maintenance", acNormal, , , acFormEdit, acDialog
End If
End Sub