473,379 Members | 1,520 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,379 software developers and data experts.

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

547 512MB
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 2089
TheSmileyCoder
2,322 Expert Mod 2GB
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 512MB
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 512MB
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, 253 views)
Nov 24 '10 #4
TheSmileyCoder
2,322 Expert Mod 2GB
You have to replace the TextBoxBoundToIdField with the name of the control containing your id field (primary key)
Nov 25 '10 #5
neelsfer
547 512MB
Thx it working 100% now
Nov 25 '10 #6
TheSmileyCoder
2,322 Expert Mod 2GB
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.