What I have seems like a hot mess to me, while the thing I'm trying to achieve seems fairly simple. Here's how I would like this to behave:
1. The user puts a number in the "Jump To" field. If the number is already in the database, it should just go to that record, and it now does that.
2. If, however, the number is NOT in the database, I want a Yes/No window to pop up displaying the number that was entered, and the question "Add the new chart number?".
3. Clicking "Yes" would add a record to the database, with the new number in the ChartNum field, close the popup, and cause the parent form to go to the new record.
4. Clicking "No" would close the "Yes/No" window, and leave the parent form exactly as it was, with the "Jump To" field blank.
Currently, the user has to re-enter the number if they do want to add it, and if they don't want to add anything, closing the popup window (the current one) generates another "Item not in list" error box. And the user has to go to the new record herself, but it is also not always available to "jump to".
I just seem to have a lot of little scraps of code that don't play well together, and I don't know enough about the different events involved to know where is the best place to do all this. Somehow, it seems that I shouldn't have to have a separate form-based-on-the-database just to add a new record, but I don't know any other way to do that. Here are the different chunks of code, in the order they are happening:
The unbound field Jump To on the form Patient_IUR_Overview has the following 2 routines:
Jump_To_AfterUpdate jumps to the record that matches the user's input, and seems to work correctly:
Expand|Select|Wrap|Line Numbers
- Private Sub Jump_To_AfterUpdate()
- On Error GoTo Err_Jump_To_AfterUpdate
- ' Find the record that matches the control.
- Dim rs As Object
- Set rs = Me.Recordset.Clone
- If Jump_To > "" Then
- rs.FindFirst "[Patient Index] = " & Str(Nz(Me![Jump_To], 0))
- If Not rs.EOF Then Me.Bookmark = rs.Bookmark
- End If
- Me![Jump_To] = ""
- Exit_Jump_To_AfterUpdate:
- Exit Sub
- Err_Jump_To_AfterUpdate:
- MsgBox Err.Description
- Resume Exit_Jump_To_AfterUpdate
- End Sub
Expand|Select|Wrap|Line Numbers
- Private Sub Jump_To_NotInList(NewData As String, Response As Integer)
- On Error GoTo Err_Jump_To_NotInList
- Dim AddNew As Boolean
- Me![Jump_To] = ""
- AddNew = MsgBox("Add a new chart number?", vbYesNo)
- If AddNew Then Add_New_Chart_Click
- AddNew = False
- Exit_Jump_To_NotInList:
- Exit Sub
- Err_Jump_To_NotInList:
- ' MsgBox Err.Description
- Resume Exit_Jump_To_NotInList
- End Sub
Expand|Select|Wrap|Line Numbers
- Private Sub Default_Invisible_Click()
- On Error GoTo err_Default_Invisible_AfterUpdate
- Call DoCmd.RunCommand(Command:=acCmdSaveRecord)
- Call DoCmd.Close
- exit_Default_Invisible_AfterUpdate:
- Exit Sub
- err_Default_Invisible_AfterUpdate:
- ' MsgBox Err.Description
- Resume exit_Default_Invisible_AfterUpdate
- End Sub
- Private Sub Form_Close()
- Requery_Open_Forms
- End Sub
Expand|Select|Wrap|Line Numbers
- Function Requery_Open_Forms()
- On Error GoTo Err_Requery_Open_Forms
- Dim lngKt As Long
- Dim lngI As Long
- Dim frm As Access.Form
- ' RequeryACollection clnOverviewClient
- If CurrentProject.AllForms("Patient_IUR_Overview").IsLoaded Then
- For lngI = 1 To lngKt
- Set frm = clnOverviewClient.Item(lngI)
- frm.Requery
- Next
- End If
- RequeryACollection clnIURClient
- RequeryACollection clnGISchedulingClient
- If CurrentProject.AllForms("Clinic_Notification").IsLoaded Then
- Forms("Clinic_Notification").Requery
- End If
- Exit_Requery_Open_Forms:
- Exit Function
- Err_Requery_Open_Forms:
- MsgBox Err.Description
- Resume Exit_Requery_Open_Forms
- End Function
You can see that this is just a tangle. What can I do to correct and streamline it?