I am writing a library (as in room full of books and things) application - client has everthing else in Access, so it is appropriate that this application is too. I am not experienced in Access and am finding it very fiddly!
The situation is that I want to use combo boxes for the input of fields that are the same over a large number of records - in this case the "collection". Most often the user simply selects a value from the list in the combo box (this bit works perfectly). Occasionally (s)he will need to add a new value, as the required value is not on the list. I want this new value to be added to the table the combo box is using, to be visible in the combo box, and to added to the data record.
Because the field in question is either "one-to-many" or "many-to-many", and because it needs to be carefully controlled we have quite an intricate network of linked tables involved. Access seems to be coping with all this fairly painlessly - until we reach this point!
Code "behind" the combo box in question :
Private Sub Collection_edit_NotInList(NewData As String, Response As Integer)
'Routine to handle case where user attempts to enter a new "Collection" name
On Error GoTo Err_Collection_edit_NotInList
NewData = Capitalise(DataTrim(NewData))
Response = acDataErrContinue
If MsgBox("'" & NewData & "' is not an existing collection. Would you like to add this collection now?", vbYesNo + vbQuestion + vbDefaultButton1, "Collection not found..."
= vbNo Then
Me.Collection_edit.Undo
Me.Collection_edit.Dropdown
Exit Sub
Else
DoCmd.OpenForm "Add a new collection", , , , acFormAdd
Forms![Add a new collection].[collection_name] = NewData
newcode = Code3letter(NewData, ""
Forms![Add a new collection].[collection_ID] = newcode
Stop
'Me.Collection_edit.Undo
'Forms![Add a new collection].SetFocus
'DoCmd.Close , , acSaveYes
End If
This works nicely down to the "stop" - the remmed lines following are attempts of mine to close off the routine satisfactorily - the new data has been added to the table, but does not appear in the combo box, is not available for selection, and the original form seems to be pointing to a different record!
("Capitalise" is a function that puts everything into lowercase except for the first letters of words other than ones like "and", "or", "of" etc. - "Code3letter" is a function to generate a unique ID for the new item - they work fine.)
This is driving me even more crazy than I already was.
The situation is that I want to use combo boxes for the input of fields that are the same over a large number of records - in this case the "collection". Most often the user simply selects a value from the list in the combo box (this bit works perfectly). Occasionally (s)he will need to add a new value, as the required value is not on the list. I want this new value to be added to the table the combo box is using, to be visible in the combo box, and to added to the data record.
Because the field in question is either "one-to-many" or "many-to-many", and because it needs to be carefully controlled we have quite an intricate network of linked tables involved. Access seems to be coping with all this fairly painlessly - until we reach this point!
Code "behind" the combo box in question :
Code:
'Routine to handle case where user attempts to enter a new "Collection" name
On Error GoTo Err_Collection_edit_NotInList
NewData = Capitalise(DataTrim(NewData))
Response = acDataErrContinue
If MsgBox("'" & NewData & "' is not an existing collection. Would you like to add this collection now?", vbYesNo + vbQuestion + vbDefaultButton1, "Collection not found..."
Me.Collection_edit.Undo
Me.Collection_edit.Dropdown
Exit Sub
Else
DoCmd.OpenForm "Add a new collection", , , , acFormAdd
Forms![Add a new collection].[collection_name] = NewData
newcode = Code3letter(NewData, ""
Forms![Add a new collection].[collection_ID] = newcode
Stop
'Me.Collection_edit.Undo
'Forms![Add a new collection].SetFocus
'DoCmd.Close , , acSaveYes
End If
Code:
This works nicely down to the "stop" - the remmed lines following are attempts of mine to close off the routine satisfactorily - the new data has been added to the table, but does not appear in the combo box, is not available for selection, and the original form seems to be pointing to a different record!
("Capitalise" is a function that puts everything into lowercase except for the first letters of words other than ones like "and", "or", "of" etc. - "Code3letter" is a function to generate a unique ID for the new item - they work fine.)
This is driving me even more crazy than I already was.