Īđč đāįđāáîōęå áāį äāííûõ äîâîëüíî ÷āņōî čņīîëüįķūōņ˙ ņīđāâî÷íûå ōāáëčöû äë˙ īîäņōāíîâęč íāáîđā įíā÷åíčé.  ņëķ÷āå åņëč ũōā ōāáëčöā čėååō îäíî īîëå äë˙ äîáāâëåíč˙ íîâîãî įíā÷åíč˙ ÷åđåį ņîáûōčå NotInList ņīčņęā ėîæíî čņīîëüįîâāōü äāííķū ôķíęöčū.
Âûīîëíčōå ņëåäķūųčå øāãč:
1. |
Īîėåņōčōå ôķíęöčū â äîņōķīíûé ėîäķëü. |
2. |
 ņâîéņōâî ņīčņęā Row Source īîėåņōčōü SQL įāīđîņ íā īîëķ÷åíčå äāííûõ čį ōđåáķåėîé ōāáëčöû |
3. |
Âûņōāâōå įíā÷åíčå ņâîéņōâā ņīčņęā LimitToList â Yes |
4. |
 îáđāáîōęå ņîáûōč˙ NotInList īîėåņōčōå Response = AppendLookupTable(Me![MyCombo], NewData) |
Public Function AppendLookupTable(cbo As ComboBox, NewData As Variant, Optional blnMsg As Boolean = True) As Integer
Dim rst As DAO.Recordset
Dim Response As Long
On Error GoTo m1
AppendLookupTable = acDataErrContinue
If Not (IsNull(NewData)) Then
If blnMsg Then
Response = MsgBox("Įíā÷åíčå [" & NewData & "] îōņķōņōâķåō â ņīčņęå." & vbCrLf & "Äë˙ äîáāâëåíč˙ íāæėčōå ÎĘ.", vbOKCancel + vbQuestion, "Äîáāâëåíčå įíā÷åíč˙")
Else
Response = 1
End If
Select Case Response
Case 1
Set rst = CurrentDb.OpenRecordset(cbo.RowSource)
rst.AddNew
rst(0) = NewData
rst.Update
rst.Close
AppendLookupTable = acDataErrAdded
Case 2
Exit Function
End Select
End If
m2:
Set rst = Nothing
Exit Function
m1:
MsgBox "Îøčáęā " & Err.Number & ": " & Err.Description, vbInformation, " â ôķíęöčč AppendLookupTable"
Resume m2
End Function
Ķäāëåíčå äāííûõ čį ņīčņęā
Public Function DeleteLookupTable(cbo As ComboBox, Optional blnMsg As Boolean = True)
Dim rst As DAO.Recordset
Dim Response As Long
On Error GoTo m1
If Not (IsNull(cbo)) Then
If blnMsg Then
Response = MsgBox("Ķäāëčōü įíā÷åíčå [" & cbo & "] čį ņīčņęā?" & vbCrLf & "Äë˙ ķäāëåíč˙ íāæėčōå ÎĘ.", vbOKCancel + vbQuestion, "Ķäāëåíčå įíā÷åíč˙")
Else
Response = 1
End If
Select Case Response
Case 1
Set rst = CurrentDb.OpenRecordset(cbo.RowSource, dbOpenDynaset)
rst.FindFirst rst(0).Name & "='" & cbo & "'"
rst.Delete
rst.Close
cbo = Null
cbo.Requery
Case 2
Exit Function
End Select
End If
m2:
Set rst = Nothing
Exit Function
m1:
MsgBox "Îøčáęā " & Err.Number & ": " & Err.Description, vbInformation, " â ôķíęöčč DeleteLookupTable"
Resume m2
End Function