M
Meirans-Mertens
In a form (Access 97, Win98), I have a combo box that lists the names of
several properties. The combo box is labeled "Property" and relies on an
underlying lookup table called "Property Names." Users can pick a name in
the list OR they can type a new name (i.e., NewData). In the latter case, a
message appears telling them that the name is not in the list, and ask them
whether they want to add it to the list. If they click No, the new name is
not retained in the field and is not added to the list. If they click Yes,
the name is added to the lookup table and remains available for all
subsequent data entry. To perform this automation, I use a VB procedure that
I found years ago in an issue of "Inside MS Access" (December 1998). It is
attached to the "On Not in List" property of the combo box (located in the
Event Property Sheet). The code is reproduced below. My question is: Is it
possible to amplify this procedure so that, when users have selected a name
in the list and when they press the Delete key (or Ctrl+X), a message would
appear telling them that they are about to delete the name and ask them
whether they want to delete it from the list? If they click No, nothing
would happen, and if they clcik Yes, the name would effectively be deleted
from the underlying lookup table. Although the selected name would remain in
the field of previously entered data, it would not appear anymore in the
combo box. If this is possible, then what would be the code? Thanks in
advance for any input you might have. (One method to turn around this
problem is to access the lookup table and delete the selected name therein.
However, this method is not elegant and I'd rather avoid making tables
available to the users.)
Here's the code. It works nicely, facilitates data entry, and helps greatly
in reducing data entry errors such as mispellings, etc. If you want to use
it, you'll need to set the combo box's "Limit to List" property to Yes and
the "Locked" property to No (both are located in the Data Property Sheet).
Private Sub Property_NotInList(NewData As String, Response As Integer)
Dim rst As Recordset
Dim Msg As String
Dim UserResponse As Integer
Msg = NewData & " is not in the list." & vbCr & "Would you like to add it?"
UserResponse = MsgBox(Msg, vbYesNo + vbQuestion, "Please Verify")
If UserResponse = vbYes Then
Set rst = CurrentDb.OpenRecordset("Property Names")
With rst
.AddNew
![Property Name] = NewData
.Update
End With
Response = acDataErrAdded
rst.Close
Set rst = Nothing
Else
Response = acDataErrContinue
Me![Property].Undo
End If
End Sub
several properties. The combo box is labeled "Property" and relies on an
underlying lookup table called "Property Names." Users can pick a name in
the list OR they can type a new name (i.e., NewData). In the latter case, a
message appears telling them that the name is not in the list, and ask them
whether they want to add it to the list. If they click No, the new name is
not retained in the field and is not added to the list. If they click Yes,
the name is added to the lookup table and remains available for all
subsequent data entry. To perform this automation, I use a VB procedure that
I found years ago in an issue of "Inside MS Access" (December 1998). It is
attached to the "On Not in List" property of the combo box (located in the
Event Property Sheet). The code is reproduced below. My question is: Is it
possible to amplify this procedure so that, when users have selected a name
in the list and when they press the Delete key (or Ctrl+X), a message would
appear telling them that they are about to delete the name and ask them
whether they want to delete it from the list? If they click No, nothing
would happen, and if they clcik Yes, the name would effectively be deleted
from the underlying lookup table. Although the selected name would remain in
the field of previously entered data, it would not appear anymore in the
combo box. If this is possible, then what would be the code? Thanks in
advance for any input you might have. (One method to turn around this
problem is to access the lookup table and delete the selected name therein.
However, this method is not elegant and I'd rather avoid making tables
available to the users.)
Here's the code. It works nicely, facilitates data entry, and helps greatly
in reducing data entry errors such as mispellings, etc. If you want to use
it, you'll need to set the combo box's "Limit to List" property to Yes and
the "Locked" property to No (both are located in the Data Property Sheet).
Private Sub Property_NotInList(NewData As String, Response As Integer)
Dim rst As Recordset
Dim Msg As String
Dim UserResponse As Integer
Msg = NewData & " is not in the list." & vbCr & "Would you like to add it?"
UserResponse = MsgBox(Msg, vbYesNo + vbQuestion, "Please Verify")
If UserResponse = vbYes Then
Set rst = CurrentDb.OpenRecordset("Property Names")
With rst
.AddNew
![Property Name] = NewData
.Update
End With
Response = acDataErrAdded
rst.Close
Set rst = Nothing
Else
Response = acDataErrContinue
Me![Property].Undo
End If
End Sub