TIP:(aanpassing 5) Access 2.0
use of OnNotInList property
substitude these variabels with your own:
X1=name combobox field in origin form
X2=(in case of subform format : mainform!subform.Form)
X3=name targetfield in targetform
Y=name of target form
Z=name of tabel in target form
Make a new module or add a function to an existing module
Function basnotlisted (NewData As String, Response As Integer,_frmName
As String)
On Error GoTo Err_basnotlisted
DoCmd DoMenuItem A_FORMBAR, A_EDIT, A_UNDOFIELD,,A_MENU_VER20
If MsgBox("""" & NewData & """ is not in the list. Add it?", 33) <> 1 Then
Response = DATA_ERRCONTINUE
Exit Function
End If
DoCmd OpenForm frmName, , , , A_ADD, A_DIALOG, NewData
Response = DATA_ERRADDED
Exit_basnotlisted:
Exit Function
Err_basnotlisted:
MsgBox err & Error$
Resume Exit_basnotlisted
End Function
Make your combobox:
Sub X1_NotInList (newdata As String, response As Integer)
On Error GoTo Err_X1_NotInList
x = basnotlisted(newdata, response, "Y")
Me!X1=DLookup("X1","Z","X3"=""" & NewData & """")
'or substitute "Me" with :Forms!Mainform!X2.Form in case of a subform
Exit_X1_NotInList:
Exit Sub
Err_X1_NotInList:
MsgBox err & Error$
Resume Exit_X1_NotInList
End Sub
Add this to your targetfield in your targetform:
(make sure this is the first tabbed field)
Sub X3_GotFocus ()
On Error GoTo Err_X3_GotFocus
If Not IsNull(OpenArgs) Then
Me!X3 = OpenArgs
End If
Exit_X3_GotFocus:
Exit Sub
Err_X3_GotFocus:
MsgBox Err & Error$
Resume Exit_X3_GotFocus
End Sub
You will be able to add new records and fill them in your combobox field at
the same time!
Rob de Rijk 2 Oct 1996
Planning to add:
-2 or more origin forms!