Solved

NotInList action.  adding names

Posted on 1998-07-24
4
176 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

615 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