Solved

NotInList action.  adding names

Posted on 1998-07-24
4
167 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 200 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

706 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now