Link to home
Start Free TrialLog in
Avatar of Ned030998
Ned030998

asked on

NotInList action. adding names

Access97.  I have a form, that has a combo box showing an authors name.  User must select a name from the list, or if the name isn't in the list, the name must be added first.

The name consists of lastname and firstname.  What I want is the name entered in the author name combo box, ie
Smith, David   to appear in the first and last name boxes in the frmAddNewAuthor form.

here's what I have so far.  Sometimes it works, sometimes it strips off the odd character.  There must be a better, more reliable way of doing it.  anyway here is what I have so far.

  Dim intNewCategory As Integer
  Dim intTruncateName As Integer
  Dim strTitle As String
  Dim intMsgDialog As Integer
 
  Me![cbominAuthor] = Null
  Response = 0
     
  strTitle = "Author Not In List"
  intMsgDialog = vbYesNo + vbQuestion + vbDefaultButton1
  intNewCategory = MsgBox("Do you want to add a new Author?", intMsgDialog, strTitle)
 
  If intNewCategory = vbYes Then
       
    ' Open form.
    DoCmd.OpenForm "frmAddNewAuthor", , , , acFormAdd
    Forms![frmAddNewAuthor]![txtAuthorFirst] = Right(NewData, Len(NewData) - InStr(NewData, ",") - 1)
    Forms![frmAddNewAuthor]![txtAuthorLast] = Left(NewData, Len(NewData) - InStr(NewData, ",") - 1)
   
    End If

any better ideas of what code I should use above.

the form [frmAddNewAuthor] has two txt boxes to hold the first and last names.

The following code is on the Close cmdbutton

Private Sub cmdClose_Click()
  On Error GoTo Err_cmdClose_Click
 
  Dim x As Variant
  x = Me![cbominAuthor]
  DoCmd.Close
  Forms![frmMin]![cbominAuthor].Requery
  DoEvents
  Forms![frmMin].[cbominAuthor] = x

as I say this seems to work sometimes,but not always.

the
Avatar of Ned030998
Ned030998

ASKER

Edited text of question
Personally I always found the not in list event a bit flaky. Also your method relies on the user entering a comma or else it fails.

Why not simplify it by having the combo limit to list set to yes and add an "add new user" button. You can then open your form with 2 text boxes allowing creation of a new name (or several new names). Then requery the combo either on the on close as you have done (which means of course they need to close the form before they see the changes, something which may not be appropriate) or put the requery code behind the after update event of the form

Unless you can make the addition totally transparent to the user (e.g. by using dao in the not in list event) you are not really saving any effort by using your method. If you want the addition to be transparent you have to verify they have entered valid syntax (including the comma)...more trouble than it's worth I think.
ASKER CERTIFIED SOLUTION
Avatar of tuvi
tuvi
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I think you both have good points.  I will give your answer a go Tuvi, however, as Helicopter suggests it is probably not worth the effort.  (That is no reflection on your answer which is good).

When I use the method above for single names, ie an organisation name, where the data is stored in one field it works really well and can make data entry really quick.  But splitting two words, ie first name and last name from one field, cboMinAuthor field, into two fields is really flakey.  Especially when it relies on the user entering names in the correct order and separated by a comma.  They are never going to get that right are they!  And the users of the database will always be phoning me complaining.

Thanks for your answer and comment which were very helpful..
Ned