By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,501 Members | 2,790 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,501 IT Pros & Developers. It's quick & easy.

new record only when form launched?

P: 493
This is kind of an odd request.

I have a form with a combo box. If an item isn't in the combo box you can add it by launching a new form (using NotInList). I would like for the main form to go right to a new record when the form is launched. I have code on the Load event that does this quite nicely. However, when the form to add to the combo box is launched and then closed it automatically causes the main form to advance to the next new record. I need for the main form to stay on the record that was being filled out when the NotInList form was launched.

Is this possible? Here is the code for the main form to make it advance to a new record when it is launched:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.     DoCmd.OpenForm "Specimen", , , , acNewRec
  3.     DoCmd.GoToRecord , , acNewRec
  4. End Sub
Feb 26 '07 #1
Share this Question
Share on Google+
5 Replies

Expert Mod 10K+
P: 12,366
What's the code for the NotInList event?
Feb 26 '07 #2

P: 493
Thanks for responding!
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
  6.     CR = Chr$(13)
  8.     ' Exit this subroutine if the combo box was cleared.
  9.     If NewData = "" Then Exit Sub
  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
  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
  38. End Sub
Feb 26 '07 #3

Expert Mod 10K+
P: 12,366
I don't see any reason why it should be doing this. Code looks fine to me. Maybe someone else will have an idea. Have you tried compiling the code? What about setting a break and then stepping through the code to find the exact place when the main form jumps to a new record?
Feb 26 '07 #4

P: 493
lol, as my username implies I am very new to Access. I will try to do as you suggested but I'm not even sure where to begin! I do believe it compilies. I'm not sure how to step through?
Feb 26 '07 #5

Expert Mod 10K+
P: 12,366
A break in the code will tell the form to jump to the visual basic editor once it hits that line of code.

To insert a break, go to the line you want to stop at and press F9.

Then open the form and activate the event where the break is. This will highlight the current line in yellow. From here, you can press F8 and it will step through each line of code, processing it one at a time. After each step, check the results to see what happens.
Feb 26 '07 #6

Post your reply

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