Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

NotInList action.  adding names

Posted on 1998-07-24
4
Medium Priority
?
179 Views
Last Modified: 2008-07-03
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
0
Comment
Question by:Ned030998
  • 2
4 Comments
 

Author Comment

by:Ned030998
ID: 1957307
Edited text of question
0
 
LVL 8

Expert Comment

by:Helicopter
ID: 1957308
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.
0
 
LVL 5

Accepted Solution

by:
tuvi earned 800 total points
ID: 1957309
Ned,
I, too, use the NotInList event the way you do all the time. But I implement it differently (and I think more efficiently). I avoid doing code controlling one form from another form. Synchronizing is tough this way. Instead, I use the OpenArgs property. So, in your case, just add your string as an OpenArgs in opening form "frmAddNewAuthor" from the first form. Then in your form "frmAddNewAuthor" OpenForm event, check for this OpenArgs. If it is Null, then the form is opened normally, otherwise it is opened from your form. Then do all the handling of the string right here. On the close button, do nothing extra except for the closing statement. Now, when the "frmAddNewAuthor" returns to the first form, add the requery statement to your form.
I am sorry, I hope you understand. I know I should put in some code, but my Access is down now.
0
 

Author Comment

by:Ned030998
ID: 1957310
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


0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question