473,405 Members | 2,279 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,405 software developers and data experts.

new record only when form launched?

AccessIdiot
493 256MB
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
  5.  
Feb 26 '07 #1
5 1852
Rabbit
12,516 Expert Mod 8TB
What's the code for the NotInList event?
Feb 26 '07 #2
AccessIdiot
493 256MB
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
  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
Feb 26 '07 #3
Rabbit
12,516 Expert Mod 8TB
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
AccessIdiot
493 256MB
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
Rabbit
12,516 Expert Mod 8TB
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

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

Similar topics

15
by: Steve | last post by:
I have a form with about 25 fields. In the BeforeUpdate event of the form, I have code that sets the default value of each field to its current value. For a new record, I can put the focus in any...
8
by: Zlatko Matić | last post by:
There is a form (single form) and a combobox. I want that current record of the form is adjusted according to selected value in the combobox. Cuurrent record should be the same as the value in the...
5
by: Ross A. Finlayson | last post by:
Hi, I'm scratching together an Access database. The development box is Office 95, the deployment box Office 2003. So anyways I am griping about forms and global variables. Say for example...
3
by: N J | last post by:
Hi, I have 2 forms open at the same time, Form 1 adds information to a field on a record that Form 2 has open. It used to show the new information on Form 2 straight away in a text box but now...
6
by: MLH | last post by:
When the vehicle entry form (frmVehicleEntryForm) first opens, the additional owner SubForm control (frmAddnlOwnrListSubForm) is enabled. You can click on it and it will accept the focus. But after...
22
AccessIdiot
by: AccessIdiot | last post by:
Hello all, I have a form (frm_Entrainment) with a button that opens a 2nd form (frm_Specimen_Entrainment). The 2nd form shares an ID field with the first form (Entrainment_ID - its like opening...
4
by: Susan Bricker | last post by:
I have a form that displays record information in Continuous Record display (scrollable list). One of the fields in the record is an Integer value called "rcode" (reason code). But, I don't want...
4
by: limperger | last post by:
Hello everyone! Just in case anyone here has experienced this problem and knows how to deal with it: I have 2 forms from 2 related tables. We have more than 600 records in the first one and of...
1
by: Ruben | last post by:
I created a simple form that includes a hyperlink field which when clicked, launches any given pdf file saved in a multi-user network. The problem is: It ONLY seems to work well when launched...
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: 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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.