473,396 Members | 1,938 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

OnNotInList - tweaking pasted code

AccessIdiot
493 256MB
I know I know, I'm the worst kind of coder. I am working on my first big Access project and with no formal training I am sort of stumbling my way through. I haven't worked with VB since college about 5 years ago.

I am trying to add a new item to a combo box by opening a new form. Here is my setup:
Specimen form has combo box Species_Code. Type something into Species_Code and if it's not there you get the pop up "Want to add?" if Yes then open Species form, type in a new species including other fields in that table (common name, scientific name, genus, etc). Then close the form and go on your merry way with the Specimen form.

Anyway, I copied this from a Microsoft suggested code page:

On the Species_Code combo box on the Specimen form:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Species_Code_NotInList(NewData As String, Response As Integer)
  2. Dim Result
  3. Dim Msg As String
  4. Dim CR As String
  5.  
  6.     CR = Chr$(13)
  7.  
  8.     If NewData = "" Then Exit Sub
  9.  
  10.     Msg = "'" & NewData & "' is not in the list." & CR & CR
  11.     Msg = Msg & "Do you want to add it?"
  12.     If MsgBox(Msg, vbQuestion + vbYesNo) = vbYes Then
  13.        DoCmd.OpenForm "Species", , , , acAdd, acDialog, NewData
  14.     End If
  15.  
  16.     Result = DLookup("[Species_Code]", "Species", _
  17.              "[Species_Code]='" & NewData & "'")
  18.     If IsNull(Result) Then
  19.        Response = acDataErrContinue
  20.        MsgBox "Please try again!"
  21.     Else
  22.        Response = acDataErrAdded
  23.     End If
  24. End Sub
  25.  

And on the Species form
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.    If Not IsNull(Me.OpenArgs) Then
  3.       Me![Species_Code] = Me.OpenArgs
  4.    End If
  5. End Sub
  6.  
Here's what happens: everything seems to work fine except that when the Species form opens it doesn't go to the last/new record in the table (there are already 100 species in the table, hence the drop down that you can add to). Instead it shows record 1 or 1 and the autonumber primary key is something like 1304579 instead of 101.

When I open the Species table the record was added but again the autonumber primary key is that weird number and not the logical next increment.

Any ideas?

And if I may be so bold - is there any way to prevent someone from continuing to work on the Specimen form if the add new species function/form is firing?

thanks, i love communities like this one.

melissa (the Access Idiot)
Feb 23 '07 #1
28 2176
Rabbit
12,516 Expert Mod 8TB
I know I know, I'm the worst kind of coder. I am working on my first big Access project and with no formal training I am sort of stumbling my way through. I haven't worked with VB since college about 5 years ago.

I am trying to add a new item to a combo box by opening a new form. Here is my setup:
Specimen form has combo box Species_Code. Type something into Species_Code and if it's not there you get the pop up "Want to add?" if Yes then open Species form, type in a new species including other fields in that table (common name, scientific name, genus, etc). Then close the form and go on your merry way with the Specimen form.

Anyway, I copied this from a Microsoft suggested code page:

On the Species_Code combo box on the Specimen form:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Species_Code_NotInList(NewData As String, Response As Integer)
  2. Dim Result
  3. Dim Msg As String
  4. Dim CR As String
  5.  
  6.     CR = Chr$(13)
  7.  
  8.     If NewData = "" Then Exit Sub
  9.  
  10.     Msg = "'" & NewData & "' is not in the list." & CR & CR
  11.     Msg = Msg & "Do you want to add it?"
  12.     If MsgBox(Msg, vbQuestion + vbYesNo) = vbYes Then
  13.        DoCmd.OpenForm "Species", , , , acAdd, acDialog, NewData
  14.     End If
  15.  
  16.     Result = DLookup("[Species_Code]", "Species", _
  17.              "[Species_Code]='" & NewData & "'")
  18.     If IsNull(Result) Then
  19.        Response = acDataErrContinue
  20.        MsgBox "Please try again!"
  21.     Else
  22.        Response = acDataErrAdded
  23.     End If
  24. End Sub
  25.  

And on the Species form
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.    If Not IsNull(Me.OpenArgs) Then
  3.       Me![Species_Code] = Me.OpenArgs
  4.    End If
  5. End Sub
  6.  
Here's what happens: everything seems to work fine except that when the Species form opens it doesn't go to the last/new record in the table (there are already 100 species in the table, hence the drop down that you can add to). Instead it shows record 1 or 1 and the autonumber primary key is something like 1304579 instead of 101.

When I open the Species table the record was added but again the autonumber primary key is that weird number and not the logical next increment.

Any ideas?

And if I may be so bold - is there any way to prevent someone from continuing to work on the Specimen form if the add new species function/form is firing?

thanks, i love communities like this one.

melissa (the Access Idiot)
It's acFormAdd, not acAdd.

The thing about autonumbers is that they don't renumber themselves. If you had a 100 records, then deleted all the records, the next record you add will be 101 and not 1. It's just the way autonumbers work in Access.
Feb 23 '07 #2
AccessIdiot
493 256MB
Thanks for that, but still the same problem.

So there is no way to launch the Species form to add a new species and have it go to the next new record (101)?
Feb 23 '07 #3
ADezii
8,834 Expert 8TB
I know I know, I'm the worst kind of coder. I am working on my first big Access project and with no formal training I am sort of stumbling my way through. I haven't worked with VB since college about 5 years ago.

I am trying to add a new item to a combo box by opening a new form. Here is my setup:
Specimen form has combo box Species_Code. Type something into Species_Code and if it's not there you get the pop up "Want to add?" if Yes then open Species form, type in a new species including other fields in that table (common name, scientific name, genus, etc). Then close the form and go on your merry way with the Specimen form.

Anyway, I copied this from a Microsoft suggested code page:

On the Species_Code combo box on the Specimen form:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Species_Code_NotInList(NewData As String, Response As Integer)
  2. Dim Result
  3. Dim Msg As String
  4. Dim CR As String
  5.  
  6.     CR = Chr$(13)
  7.  
  8.     If NewData = "" Then Exit Sub
  9.  
  10.     Msg = "'" & NewData & "' is not in the list." & CR & CR
  11.     Msg = Msg & "Do you want to add it?"
  12.     If MsgBox(Msg, vbQuestion + vbYesNo) = vbYes Then
  13.        DoCmd.OpenForm "Species", , , , acAdd, acDialog, NewData
  14.     End If
  15.  
  16.     Result = DLookup("[Species_Code]", "Species", _
  17.              "[Species_Code]='" & NewData & "'")
  18.     If IsNull(Result) Then
  19.        Response = acDataErrContinue
  20.        MsgBox "Please try again!"
  21.     Else
  22.        Response = acDataErrAdded
  23.     End If
  24. End Sub
  25.  

And on the Species form
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.    If Not IsNull(Me.OpenArgs) Then
  3.       Me![Species_Code] = Me.OpenArgs
  4.    End If
  5. End Sub
  6.  
Here's what happens: everything seems to work fine except that when the Species form opens it doesn't go to the last/new record in the table (there are already 100 species in the table, hence the drop down that you can add to). Instead it shows record 1 or 1 and the autonumber primary key is something like 1304579 instead of 101.

When I open the Species table the record was added but again the autonumber primary key is that weird number and not the logical next increment.

Any ideas?

And if I may be so bold - is there any way to prevent someone from continuing to work on the Specimen form if the add new species function/form is firing?

thanks, i love communities like this one.

melissa (the Access Idiot)
If you are getting 'wierd' numbers that are also 'not in sequence' in an AutoNumber Field, then check the New Values property for the Field in the Grid below. Instead of being set to Increment, you may have it set to Random.
Feb 23 '07 #4
Rabbit
12,516 Expert Mod 8TB
I'm stumped, no idea why it won't go to a new record. As far as I can tell, it should. Maybe someone else will know why.
Feb 23 '07 #5
MMcCarthy
14,534 Expert Mod 8TB
If you run compact and Repair on the database the numbers should resequence and give you 101.

Mary
Feb 23 '07 #6
AccessIdiot
493 256MB
If you are getting 'wierd' numbers that are also 'not in sequence' in an AutoNumber Field, then check the New Values property for the Field in the Grid below. Instead of being set to Increment, you may have it set to Random.

Hi, I did check and it is set to increment.

mmccarthy - is that just a temporary solution? or will that fix it so that it returns a correct number any time a new record is added?

thanks everyone!
Feb 23 '07 #7
MMcCarthy
14,534 Expert Mod 8TB
Hi, I did check and it is set to increment.

mmccarthy - is that just a temporary solution? or will that fix it so that it returns a correct number any time a new record is added?

thanks everyone!
As long as you don't start adding and deleting records it should be fine.

Mary
Feb 23 '07 #8
Rabbit
12,516 Expert Mod 8TB
As long as you don't start adding and deleting records it should be fine.

Mary
Didn't know Compact and Repair did that. Good to know.

I suppose you could set up the database to compact on close. Tools > Startup.
Feb 23 '07 #9
AccessIdiot
493 256MB
Okay I figured out what I was doing wrong but not how to fix it. See, there is good reason why I am called Access Idiot! :-)

This is so basic I know that I am embarrassed to be asking but hey, I guess we all gotta start somewhere.

So what I am doing wrong has to do with the control and row source for the combo box. I have this form for "Specimen". On the Specimen form I want to have a drop down for Gender. I want the values for the dropdown to come from the Gender table but I want the gender chosen for that particular specimen to be held in the Specimen table. Pretty basic right? So I have the primary key of the Gender table as a foreign key in the Specimen table with a one-to-many relationship (many specimens can be male).

What I'm getting caught up in is how to set this in the properties of the stupid form. How do I set the Record Source for the form? What is the control source for the combo box? What is the row source? I'm getting very confused on how to set this all up.

But I think that solving this problem will solve my weird autonumber problem. Previously I had the control source as the gender field from the gender table, so anytime I chose "male" it would add a row for male to the gender table when I already had one in there.

I tried setting the record source for the form to * of the Specimen table. Then I set the control source for the combo box to be gender_id (since that is what the specimen table holds) and the row source to gender (so you'd actually see male, female, etc in the dropdown) but even though you see the text in the drop down it is looking for a number because the gender_id is an autonumber field. Argh!

I hope this makes sense and I hope you don't think I'm so ignorant that I don't deserve an answer!
Feb 23 '07 #10
MMcCarthy
14,534 Expert Mod 8TB
Okay I figured out what I was doing wrong but not how to fix it. See, there is good reason why I am called Access Idiot! :-)

This is so basic I know that I am embarrassed to be asking but hey, I guess we all gotta start somewhere.

So what I am doing wrong has to do with the control and row source for the combo box. I have this form for "Specimen". On the Specimen form I want to have a drop down for Gender. I want the values for the dropdown to come from the Gender table but I want the gender chosen for that particular specimen to be held in the Specimen table. Pretty basic right? So I have the primary key of the Gender table as a foreign key in the Specimen table with a one-to-many relationship (many specimens can be male).

What I'm getting caught up in is how to set this in the properties of the stupid form. How do I set the Record Source for the form? What is the control source for the combo box? What is the row source? I'm getting very confused on how to set this all up.

But I think that solving this problem will solve my weird autonumber problem. Previously I had the control source as the gender field from the gender table, so anytime I chose "male" it would add a row for male to the gender table when I already had one in there.

I tried setting the record source for the form to * of the Specimen table. Then I set the control source for the combo box to be gender_id (since that is what the specimen table holds) and the row source to gender (so you'd actually see male, female, etc in the dropdown) but even though you see the text in the drop down it is looking for a number because the gender_id is an autonumber field. Argh!

I hope this makes sense and I hope you don't think I'm so ignorant that I don't deserve an answer!
Speciman form based on Speciman table with GenderID as a foreign key from speciman table. You don't need the Gender table included by query (unless you need if for something else).

Set up combo box with control source property set to GenderID, which (since Gender table isn't included in the query) will store the value in the Speciman table.

Set the following Properties of the combo box.

Under Format tab
Column Count = 2
Column Widths = 0cm; 2cm

Under Data tab
Row Source = SELECT GenderID, GenderName FROM Gender
Bound Column = 1

Mary
Feb 23 '07 #11
AccessIdiot
493 256MB
Okay this is something that really ticks me off. See, I DID all that and it wouldn't work. When I erased the combo box and used the toolbox to draw one in and go through the wizard it DID work. Why? That is incredibly frustrating.

I should mention that when I created the form I went through the wizard and added all the fields from the Specimen table, then went into each field, changed it to a combo box, and then went into the properties to set the row source, bound column, etc. Mary when I change the settings to what you suggested the combo box displays the gender id, not the gender text which is in column 2. Any ideas why?

Seems like it should work if the properties are exactly the same no matter how you get there.

thanks all for your help, i'm glad i finally fixed the problem but I'm not happy with the method.
Feb 23 '07 #12
MMcCarthy
14,534 Expert Mod 8TB
Okay this is something that really ticks me off. See, I DID all that and it wouldn't work. When I erased the combo box and used the toolbox to draw one in and go through the wizard it DID work. Why? That is incredibly frustrating.
If you haven't set the lookup list for the genderID in the table it will only come in as a textbox.

Mary when I change the settings to what you suggested the combo box displays the gender id, not the gender text which is in column 2. Any ideas why?
Did you set the column widths I gave you.
Feb 23 '07 #13
AccessIdiot
493 256MB
If you haven't set the lookup list for the genderID in the table it will only come in as a textbox.

Did you set the column widths I gave you.
I did set the column widths, thank you. That's another thing I don't get. Why do you have to set the column count to 2 and hide one? Why not just set it to the one you want to display? Kind of a weird quirk isn't it?

I did not set the lookup list. Question about that - if I set it in the table properties does that mean I can't add to it using the NotInList property?

again, thanks for all the patience and help - i am slowly getting it down!
Feb 23 '07 #14
AccessIdiot
493 256MB
Okay I am making progress. I can open a form and have it go to a blank new record and the autonumber increments just fine. I have a combo box on this form. I type something into my combo box and it opens up another form to add the data to the underlying table. However, on THAT form the auto number is huge again and not incremental. Also, when I try to add data to a combo box on THAT form I get the dreaded standard Access pop up that my data wasn't chosen from the list.

So in other words:

Specimen Form - autonumber works great; has combo box called "species" - type in and if not in list launch Species Form.

Species Form - autonumber does not work but can fill in fields; has combo box called "genus" - type in and if not in list I get standard Access error message.

Any help?

Code on Specimen Form:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Species_NotInList(NewData As String, Response As Integer)
  2. Dim Result
  3. Dim Msg As String
  4. Dim CR As String
  5.  
  6.     CR = Chr$(13)
  7.  
  8.     ' Exit this subroutine if the combo box was cleared.
  9.     If NewData = "" Then Exit Sub
  10.  
  11.     ' Ask the user if he or she wishes to add the new customer.
  12.     Msg = "'" & NewData & "' is not in the list." & CR & CR
  13.     Msg = Msg & "Do you want to add it?"
  14.     If MsgBox(Msg, vbQuestion + vbYesNo) = vbYes Then
  15.        ' If the user chose Yes, start the Species form in data entry
  16.        ' mode as a dialog form, passing the new species code name in
  17.        ' NewData to the OpenForm method's OpenArgs argument. The
  18.        ' OpenArgs argument is used in Species form's Form_Load event
  19.        ' procedure.
  20.        DoCmd.OpenForm "Species", , , , acFormAdd, acDialog, NewData
  21.     End If
  22.  
  23.     ' Look for the species code name the user created in the Specimen form.
  24.     Result = DLookup("[Species_Code]", "Species", _
  25.              "[Species_Code]='" & NewData & "'")
  26.     If IsNull(Result) Then
  27.        ' If the species code was not created, set the Response argument
  28.        ' to suppress an error message and undo changes.
  29.        Response = acDataErrContinue
  30.        ' Display a customized message.
  31.        MsgBox "Please try again!"
  32.     Else
  33.        ' If the species code was created, set the Response argument to
  34.        ' indicate that new data is being added.
  35.        Response = acDataErrAdded
  36.     End If
  37.  
  38. End Sub
Code on Species Form
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.    If Not IsNull(Me.OpenArgs) Then
  3.       Me![Species_Code] = Me.OpenArgs
  4.    End If
  5. End Sub
  6.  
  7. Private Sub Genus_NotInList(NewData As String, Response As Integer)
  8. Dim db As DAO.Database
  9. Dim rs As DAO.Recordset
  10. Dim strMsg As String
  11.  
  12.     strMsg = "'" & NewData & "' is not an available AE Name " & vbCrLf & vbCrLf
  13.     strMsg = strMsg & "Do you want to associate the new Name to the current DLSAF?"
  14.     strMsg = strMsg & vbCrLf & vbCrLf & "Click Yes to link or No to re-type it."
  15.  
  16.     If MsgBox(strMsg, vbQuestion + vbYesNo, "Add new name?") = vbNo Then
  17.         Response = acDataErrContinue
  18.     Else
  19.         Set db = CurrentDb
  20.         Set rs = db.OpenRecordset("Genus", dbOpenDynaset)
  21.         On Error Resume Next
  22.         rs.AddNew
  23.             rs!AEName = NewData
  24.         rs.Update
  25.  
  26.         If Err Then
  27.             MsgBox "An error occurred. Please try again."
  28.             Response = acDataErrContinue
  29.         Else
  30.             Response = acDataErrAdded
  31.         End If
  32.  
  33.     End If
  34.  
  35. rs.Close
  36. Set rs = Nothing
  37. Set db = Nothing
  38. End Sub
Feb 24 '07 #15
NeoPa
32,556 Expert Mod 16PB
I did set the column widths, thank you. That's another thing I don't get. Why do you have to set the column count to 2 and hide one? Why not just set it to the one you want to display? Kind of a weird quirk isn't it?

I did not set the lookup list. Question about that - if I set it in the table properties does that mean I can't add to it using the NotInList property?

again, thanks for all the patience and help - i am slowly getting it down!
Melissa (I can't call you AccessIdiot - it doesn't work for me ;)),
If you have a ComboBox where you want to return 1 value and show another, then it needs to have both the shown and the returned fields as columns. You can show both and return one, but you can't either show or return a column unless it's included in the data.
I'm afraid I didn't really follow the other question - sorry.
Feb 26 '07 #16
AccessIdiot
493 256MB
Thank you NeoPa, that makes perfect sense now. :-)

Mary check your email and thank you!

cheers,
melissa
Feb 26 '07 #17
NeoPa
32,556 Expert Mod 16PB
No Problem.
We'll make an expert of you yet. I can just see the introductory thread :
'Welcome to our newest Access Expert AccessIdiot.' :D
Feb 26 '07 #18
MMcCarthy
14,534 Expert Mod 8TB
Expand|Select|Wrap|Line Numbers
  1. Private Sub Genus_NotInList(NewData As String, Response As Integer)
  2. Dim db As DAO.Database
  3. Dim rs As DAO.Recordset
  4. Dim strMsg As String
  5.  
  6.     strMsg = "'" & NewData & "' is not an available AE Name " & vbCrLf & vbCrLf
  7.     strMsg = strMsg & "Do you want to associate the new Name to the current DLSAF?"
  8.     strMsg = strMsg & vbCrLf & vbCrLf & "Click Yes to link or No to re-type it."
  9.  
  10.     If MsgBox(strMsg, vbQuestion + vbYesNo, "Add new name?") = vbNo Then
  11.         Response = acDataErrContinue
  12.     Else
  13.         Set db = CurrentDb
  14.         Set rs = db.OpenRecordset("Genus", dbOpenDynaset)
  15.         On Error Resume Next
  16.         rs.AddNew
  17.             rs!Genus = NewData
  18.         rs.Update
  19.  
  20.         If Err Then
  21.             MsgBox "An error occurred. Please try again."
  22.             Response = acDataErrContinue
  23.         Else
  24.             Response = acDataErrAdded
  25.         End If
  26.  
  27.     End If
  28.  
  29.    rs.Close
  30.    Set rs = Nothing
  31.    Set db = Nothing
  32.    Me.Genus.Requery
  33.  
  34. End Sub
  35.  
Feb 27 '07 #19
MMcCarthy
14,534 Expert Mod 8TB
The main problem with the NotInList code was you were trying to update a non existant field.

Your code had

Expand|Select|Wrap|Line Numbers
  1.  
  2. rs!AEName = NewData
instead of

Expand|Select|Wrap|Line Numbers
  1.  
  2. rs!Genus = NewData
Feb 27 '07 #20
MMcCarthy
14,534 Expert Mod 8TB
Problem regarding checkbox on the form controlling the subform was that it was unbound. Therefore when you set it to true on one form record it was remaining true for all records. I've gotten around this by creating a field in the speciman table to store the value of this checkbox. It will now change with the forms on current event. The other problem was that the subforms data entry property was set to yes so you couldn't view existing records but only add new records. I've changed this to no.

Mary
Feb 27 '07 #21
AccessIdiot
493 256MB
The main problem with the NotInList code was you were trying to update a non existant field.

Your code had

Expand|Select|Wrap|Line Numbers
  1.  
  2. rs!AEName = NewData
instead of

Expand|Select|Wrap|Line Numbers
  1.  
  2. rs!Genus = NewData
I never would have seen that in a million years - thank you!


Problem regarding checkbox on the form controlling the subform was that it was unbound. Therefore when you set it to true on one form record it was remaining true for all records. I've gotten around this by creating a field in the speciman table to store the value of this checkbox. It will now change with the forms on current event. The other problem was that the subforms data entry property was set to yes so you couldn't view existing records but only add new records. I've changed this to no.

Mary
I knew it was unbound but didn't know how to bind it. I never would have thought to add a field to the table. I also didn't realize that the data entry property set to yes meant you couldn't view existing records? That doesn't seem intuitive. Thanks for catching that and fixing my checkbox problem as well!

I'm sure I'll be back with more problems as our forms grow. This has been a great learning experience for me though - thanks to everyone for the help and especially to Mary!
Feb 27 '07 #22
MMcCarthy
14,534 Expert Mod 8TB
No problem!

Glad to help.

Mary
Feb 27 '07 #23
AccessIdiot
493 256MB
Okay I'm back. :-) That didn't last long did it?

I've been playing with the code a bit, trying to break it (because I know the end user eventually will and they'll be stuck on a boat in another state and calling me for help on how to fix it) and of course I did. I was getting a compile error on the code on the 2nd combo box, the one for Genus on the Species form. So I got rid of it and found simpler code that I am using instead:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Genus_NotInList(NewData As String, Response As Integer)
  2.     Dim strSQL As String
  3.     Dim i As Integer
  4.     Dim Msg As String
  5.  
  6.     'Exit this sub if the combo box is cleared
  7.     If NewData = "" Then Exit Sub
  8.  
  9.     Msg = "'" & NewData & "' is not currently in the list." & vbCr & vbCr
  10.     Msg = Msg & "Do you want to add it?"
  11.  
  12.     i = MsgBox(Msg, vbQuestion + vbYesNo, "Unknown Genus Category...")
  13.     If i = vbYes Then
  14.         strSQL = "Insert Into Genus ([Genus]) " & _
  15.                  "values ('" & NewData & "');"
  16.         CurrentDb.Execute strSQL, dbFailOnError
  17.         Response = acDataErrAdded
  18.     Else
  19.         Response = acDataErrContinue
  20.     End If
  21. End Sub
  22.  
This works great! Except I am still having problem with the autonumber not incrementing and giving me huge weird numbers, both for the new species that was added to the combo box on Specimen and to the new genus that was added to the combo box on Species.

Any ideas why this is so?

Also, when I close the form that adds a new Species the Specimen form advances to a new record. But I would like it to remain on the current record in case the user hasn't filled out all the information on the form. I want them to have to advance to a new record when they are ready. Is there any way to set this up?

Note that I do have some code on the Specimen form that causes it to open to a new/blank record when it is launched (the onload event) but I was hoping that wouldn't fire when the form is already opened. Could it be interfering?
Feb 27 '07 #24
MMcCarthy
14,534 Expert Mod 8TB
Okay I'm back. :-) That didn't last long did it?

I've been playing with the code a bit, trying to break it (because I know the end user eventually will and they'll be stuck on a boat in another state and calling me for help on how to fix it) and of course I did. I was getting a compile error on the code on the 2nd combo box, the one for Genus on the Species form. So I got rid of it and found simpler code that I am using instead:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Genus_NotInList(NewData As String, Response As Integer)
  2.     Dim strSQL As String
  3.     Dim i As Integer
  4.     Dim Msg As String
  5.  
  6.     'Exit this sub if the combo box is cleared
  7.     If NewData = "" Then Exit Sub
  8.  
  9.     Msg = "'" & NewData & "' is not currently in the list." & vbCr & vbCr
  10.     Msg = Msg & "Do you want to add it?"
  11.  
  12.     i = MsgBox(Msg, vbQuestion + vbYesNo, "Unknown Genus Category...")
  13.     If i = vbYes Then
  14.         strSQL = "Insert Into Genus ([Genus]) " & _
  15.                  "values ('" & NewData & "');"
  16.         CurrentDb.Execute strSQL, dbFailOnError
  17.         Response = acDataErrAdded
  18.     Else
  19.         Response = acDataErrContinue
  20.     End If
  21. End Sub
  22.  
This works great! Except I am still having problem with the autonumber not incrementing and giving me huge weird numbers, both for the new species that was added to the combo box on Specimen and to the new genus that was added to the combo box on Species.

Any ideas why this is so?

Also, when I close the form that adds a new Species the Specimen form advances to a new record. But I would like it to remain on the current record in case the user hasn't filled out all the information on the form. I want them to have to advance to a new record when they are ready. Is there any way to set this up?

Note that I do have some code on the Specimen form that causes it to open to a new/blank record when it is launched (the onload event) but I was hoping that wouldn't fire when the form is already opened. Could it be interfering?
Leave this with me for a while. I'll play around a bit and get back to you tomorrow.

Mary
Feb 27 '07 #25
AccessIdiot
493 256MB
Thanks Mary!
Feb 27 '07 #26
NeoPa
32,556 Expert Mod 16PB
I go away for five minutes and come back to find 490 (odd) new posts :(
I presume from the back-and-forth that the two of you are working on an e-mailed version of the actual database rather than intuitively from what's been posted?
Good work anyway Mary - not been idle again I see :)
Feb 27 '07 #27
AccessIdiot
493 256MB
Yes I emailed a copy to Mary but nothing much has been changed from what has been posted. I am happy to send you a copy if you have any ideas! :-D
Feb 27 '07 #28
NeoPa
32,556 Expert Mod 16PB
Thanks for the offer Melissa, but I'll take a pass.
I just wanted to make it plain to any other readers of the thread that this had happened and I'm not remotely 'jealous' of the attention Mary has deservedly got from her work.
One of her answers was posted which referenced information which wasn't publicly available, so I guessed, and thought it a good idea to make it clear.
I'll help where I can of course, but if you have Mary on your thread you don't often need anyone else ;)
Feb 27 '07 #29

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: Sandy Norton | last post by:
If we are going to be stuck with @decorators for 2.4, then how about using blocks and indentation to elminate repetition and increase readability: Example 1 --------- class Klass: def...
3
by: MaryO | last post by:
I was hoping someone could help me with the OnNotInList function from Access. I downloaded this code below. I keep getting an error on the fAddToList – Sub or Function not defined. Please help...
3
by: rdi | last post by:
The import statements weren't copy/pasted, but everything INSIDE the class WAS copy pasted from the help file. Starting with the myMail.From line and going down to the SmtpMail.Send line, EVERY line...
13
by: Keith Wilby | last post by:
I've never used this event before and I'm struggling. I have this code in it: If MsgBox("You entered " & Me.cboManagerName _ & " - is this the manager's network logon ID?", vbYesNo, "Confrim...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.