Solved

NotInList action.  adding names

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
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…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

919 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

16 Experts available now in Live!

Get 1:1 Help Now