473,467 Members | 1,992 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Go to specific field in form using "on not in list " in access

547 Contributor
I have a combobox in a form that looks up records based on this form itself(cyclist tbl).I also add new records to this same form if i cant find the IDNo of a person in this combobox. If i type in the IdNo of a person in the combobox and dont find it, then i want to move straight to the IDNumber field (first field on the form) called IdNo with the "on not in list" and create a new record to start entering immediately.
Combo is called = Combo177
Form = cyclistf
Table = cyclist
fields:
IdNo = primary key + txt
Surname = txt
Name = txt
Gender = txt

This code ask the right questions, but dont copy this IdNo that it cant find into a new blank field for me. If i say no, then it gets into a loop and you can't get out until you say yes it must add it, which it does not do properly. I need to refresh the data somehow i think.
pls help!!

Expand|Select|Wrap|Line Numbers
  1. Private Sub Combo177_NotInList(NewData As String, Response As Integer)
  2.  
  3.     On Error GoTo Combo177_NotInList_Err
  4.     Dim intAnswer As Integer
  5.     Dim strSQL As String
  6.     intAnswer = MsgBox("The Id number " & Chr(34) & NewData & _
  7.         Chr(34) & " is not currently listed." & vbCrLf & _
  8.         "Would you like to add it to the list now?" _
  9.         , vbQuestion + vbYesNo, "Entries")
  10.     If intAnswer = vbYes Then
  11.         strSQL = "INSERT INTO Cyclist([IdNo]) " & _
  12.                  "VALUES ('" & NewData & "');"
  13.         DoCmd.SetWarnings False
  14.         DoCmd.RunSQL strSQL
  15.         DoCmd.SetWarnings True
  16.         MsgBox "The new Id number has been added to the list." _
  17.             , vbInformation, "Entries"
  18.         Response = acDataErrAdded
  19.  
  20.  
  21.     Else
  22.         MsgBox "Please choose an Id Number from the list." _
  23.             , vbInformation, "Entries"
  24.         Response = acDataErrContinue
  25.         DoCmd.GoToRecord , "", acNewRec
  26.     End If
  27. Combo177_NotInList_Exit:
  28.     Exit Sub
  29. Combo177_NotInList_Err:
  30.     MsgBox Err.Description, vbCritical, "Error"
  31.     Resume Combo177_NotInList_Exit
  32.  
  33. End Sub
Nov 24 '10 #1

✓ answered by TheSmileyCoder

Im really at a loss to understand your points. You say one thing in your post, and then do the complete opposite in your code.

If you select yes, to the msgbox, you create the record, but don't go to it. If you select yes, you tell the user to try again, but use the code to go to a new blank record.

Anyways, I have made some modifications. I also STRONGLY suggest a more appropriate name then combobox177, an example could be: cmb_SelectCyclist
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmb_SelectCyclist_NotInList(NewData As String, Response As Integer)
  2. 'This combobox is used to navigate the form, or as a means to go to a new record for unknown cyclists.
  3. If vbYes= MsgBox("The Id number " & Chr(34) & NewData & _
  4.           Chr(34) & " is not currently listed." & vbCrLf & _
  5.           "Would you like to add it to the list now?" _
  6.           , vbQuestion + vbYesNo, "Entries") Then
  7.   me.cmb_Cyclist.Undo
  8.   Response=acDataErrContinue
  9.   DoCmd.GoToRecord , "", acNewRec
  10.   me.TextBoxBoundToIdField=newData
  11. else
  12.   Me.cmb_Cyclist.Undo
  13.   Response =acDataErrContinue 
  14. End If
  15. End Sub
  16.  
I dont have time to add more detailed comments/description,but hope you can either use this, or that it will point you in the right direction.

6 2126
TheSmileyCoder
2,322 Recognized Expert Moderator Top Contributor
Im really at a loss to understand your points. You say one thing in your post, and then do the complete opposite in your code.

If you select yes, to the msgbox, you create the record, but don't go to it. If you select yes, you tell the user to try again, but use the code to go to a new blank record.

Anyways, I have made some modifications. I also STRONGLY suggest a more appropriate name then combobox177, an example could be: cmb_SelectCyclist
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmb_SelectCyclist_NotInList(NewData As String, Response As Integer)
  2. 'This combobox is used to navigate the form, or as a means to go to a new record for unknown cyclists.
  3. If vbYes= MsgBox("The Id number " & Chr(34) & NewData & _
  4.           Chr(34) & " is not currently listed." & vbCrLf & _
  5.           "Would you like to add it to the list now?" _
  6.           , vbQuestion + vbYesNo, "Entries") Then
  7.   me.cmb_Cyclist.Undo
  8.   Response=acDataErrContinue
  9.   DoCmd.GoToRecord , "", acNewRec
  10.   me.TextBoxBoundToIdField=newData
  11. else
  12.   Me.cmb_Cyclist.Undo
  13.   Response =acDataErrContinue 
  14. End If
  15. End Sub
  16.  
I dont have time to add more detailed comments/description,but hope you can either use this, or that it will point you in the right direction.
Nov 24 '10 #2
neelsfer
547 Contributor
thx i will give it a try. sorry i copied this code from somewhere on the web and try to make it work. I am a bit of a novice at vba
Nov 24 '10 #3
neelsfer
547 Contributor
this line seems to give vba error
Expand|Select|Wrap|Line Numbers
  1. Me.TextBoxBoundToIdField = NewData
see pic pls. i changed the combobox title
Attached Images
File Type: jpg nonnotinlisterror.jpg (64.8 KB, 254 views)
Nov 24 '10 #4
TheSmileyCoder
2,322 Recognized Expert Moderator Top Contributor
You have to replace the TextBoxBoundToIdField with the name of the control containing your id field (primary key)
Nov 25 '10 #5
neelsfer
547 Contributor
Thx it working 100% now
Nov 25 '10 #6
TheSmileyCoder
2,322 Recognized Expert Moderator Top Contributor
Im smiling to hear that.
Nov 25 '10 #7

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

Similar topics

3
by: Luiz Siqueira Neto | last post by:
Somebody know how make html forms or python forms inside html to use as gui application? The idea is make a client application like a web site of my interprise for customers who don't have good...
2
by: Danny | last post by:
Hello I am trying to create a separate listbox and fill it with items based on what is in another field in a database. This field is bound to a field in the underlying database. But the data...
1
by: Bob Alston | last post by:
I am trying to highlight required data fields in a continuous form situation. Got it working for all but date fields. For date fields, I am trying setting default date to -1 (=12/29/1899) and...
2
by: jerry.ranch | last post by:
I'm starting to learn about the tab control. How would I write an on open event procedure in VBA, that upon opening of the form, a specific tab opens (say tab 1)? Thanks Jerry
3
by: RR | last post by:
I have a button on a form (form A) that opens another form. The form that opens (form B) has a listbox that is populated with a call to a function in the "on current" event. When form B with the...
2
by: Serious_Practitioner | last post by:
Good day, and thank you in advance for any assistance. I'm having trouble with something that I'm trying for the first time. Using Access 2000 - I want to run a function either on the click of a...
3
by: warnold | last post by:
my table contains a lot of fields, so i want to create a form with a combo box and a (probably) text box that goes like this... the combo box display the fields in the table. (this i've already...
4
by: belfallas | last post by:
Hi, ive got this problem with one of my databeses. My question is, how do i create a sort of a shopping list on access? Im doing a ficitional pizza shop, and what i want to do is to have an...
1
by: m-sjoblom | last post by:
Hi On a form listbox Access version 2003 has a limited number or characters that can be stored in a listbox when the Row source Type is set to "Value List". Is there anybody that knows the...
7
kcdoell
by: kcdoell | last post by:
Hello: I have a form that I want to open using a filter that I have created. I have done this usually by pointing the record source of the form to the query/filter that I created. In this new...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...
1
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

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.