Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening data entry form On Not in List 1

Status
Not open for further replies.

tempclerk

Technical User
Jun 26, 2001
292
US
Since I cannot write code myself, I copied the following code from an old post and got it working in my database, but I would like it to copy the name already entered in the cboTo combo box so that the user doesn't have to retype it in the frmFaxListAddContact entry form.

Private Sub cboTo_NotInList(NewData As String, Response As Integer)
On Error GoTo cboTo_NotInList_Err
'Add a new record to the FaxList table
'and requery the cboTo combo box
Dim NewContact As Integer, MsgTitle As String, MsgDialog As Integer
Const MB_YESNO = 4
Const MB_ICONEXCLAMATION = 48
Const MB_DEFBUTTON1 = 0, IDYES = 6, IDNO = 7
'Make sure the user really wants to add it
MsgTitle = "Contact is not in the list"
MsgDialog = MB_YESNO + MB_ICONEXCLAMATION + MB_DEFBUTTON1
NewContact = MsgBox("Do you want to add the new Contact?", MsgDialog, MsgTitle)
If NewContact = IDNO Then
Response = DATA_ERRCONTINUE
' Display a customized message.
MsgBox "You have chosen NOT to enter a new Contact. Please choose a name from the list."
Else
DoCmd.OpenForm "frmFaxListAddContact", acNormal, , , acAdd, acDialog
Response = DATA_ERRADDED
End If
cboTo_Exit:
Exit Sub
cboTo_NotInList_Err:
MsgBox Err.Description
Resume cboTo_Exit
End Sub



I tried adding this line:

Forms!frmFaxListAddContact.txtContact = Forms!frmSelect1.cboTo.Text

after the DoCmd.Openform, but since the frmFaxListAddContact form was opened acDialog, the code did not execute. When I removed the ", acDialog", the name was set in the frmFaxListAddContact form, but then the rest of the code immediately executed and I got the generic Not in List error message without getting the chance to complete the new entry.

Would the thing to do be to pause the code until the frmFaxListAddContact form is closed, and if so, how do I do this?
 
dear tempclerk,

the last option of the open command is written to the openargs property of the form you are opening

DoCmd.OpenForm "frmFaxListAddContact", acNormal, , , acAdd, acDialog,Forms!frmSelect1.cboTo.Text

then in the form_open event you put:
Forms!frmFaxListAddContact.txtContact = me.openargs

i did not test it, but it should do,

regards astrid
 
Try setting the Default value on the txtContact control on the FaxListAddContact form to "= Forms!frmSelect1.cboTo.Text"... I'm not sure if that will work if not, it'd be some of that nasty code. The dialog option forces the code to stop executing...
 
Astrid,
Sounds simple; I'll try it. This won't cause problems if the data entry form is opened from elsewhere, will it? Also, what if there were other fields I wanted to set at the same time? (There aren't here, but it might be useful in another database where I use a macro.)
 
dear lameid,

if it works (and it should), that is really

coooooool

regards astrid
 
dear tempclerk

if you also open that form from somewhere else, you should do in the open event:

if not isnull(me.openargs) then
Forms!frmFaxListAddContact.txtContact = me.openargs
end if

as openargs is a normal string you could paste the arguments separated by ";" or any character that is not in the strings you want and than use the split-function to pass it into an array, like this

dim my_array() as string 'you may not put any values into the brackets
my_array = split(me.openargs, ";")

then you can check ubound(my_array) for the amount of args passed

and use the values in the array to pass it whereever you want.

regards astrid


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top