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

Which event do I use when a record can't be found with key matching fields

I'm working in access 2002. I have three tables :
1- District Data (Student ID, name, grade, etc)
2- Rosters (RRec ID,Campus, Teacher ID)
3- Students on Roster(SRec ID, RRec ID, Student ID)

There's a 1 to many relationship between Rosters and Students on Roster. I created a form and subform to populate the Rosters and Students on Roster.

The Students on Roster subform simply accepts the Student ID's (datasheet format) and if the student is found in the District Data table it displays their data on the screen. I created a relationship between District Data and Students on roster based on Student ID.

I did not use a combo box on purpose, since I want to make sure the data entry clerk verifies the data associated with the student id.

My problem is that when the student is not on the District Data table (cannot find record in the table District Data with key matching field(s) Student ID). I want to launch a data entry screen (another form in dialog mode) to collect the data for the District Data table and pass it back to the original form for display. What event do I use?

I have found quite a bit using combo boxes and the NotInList event, but that will allow for error since it prefills the student id field.

I am a VB newbie. :-( Any help will be greatly appreciated.
Apr 25 '07 #1
18 2629
NeoPa
32,556 Expert Mod 16PB
What are you using to determine if there is a matching record in the [District Data] table (DLookup; Linked fields; Within the RecordSource query)?
Apr 26 '07 #2
What are you using to determine if there is a matching record in the [District Data] table (DLookup; Linked fields; Within the RecordSource query)?
I don't know how to do DLookup. I have a relationship between District Data and Students in Roster based on Student ID. I built Form1 using the Student ID field in Students in Roster and pulled the corresponding fields from District Data for that Student ID. When it can't find the corresponding record in District Data (error - cannot find record in the table District data with key matching field(s) Student ID), I want to launch the new Form2 to give them an opportunity to add it and go back to the original Form1 to continue entering more students.
Apr 26 '07 #3
NeoPa
32,556 Expert Mod 16PB
I get what you want, but until I understand how you're getting that error message I can't tell you how to do it. I get that it's not DLookup(), but what is it?
Apr 26 '07 #4
I get what you want, but until I understand how you're getting that error message I can't tell you how to do it. I get that it's not DLookup(), but what is it?
The forms record source is
Expand|Select|Wrap|Line Numbers
  1. SELECT Students on Roster.StudentID, District Data.First, District Data.Last, District Data.Grade, Students on Roster.RostertID FROM District Data INNER JOIN Students on Roster ON District Data.StudentID=Students on Roster.StudentID;
I'm thinking I have setup the form wrong from the get go. It did get the form to display how I want, but it's limiting me to what I can do. I'm thinking a join is not made for lookups. I'm looking at MS office to see how DLookup works. Any suggestions will be APPRECIATED. I'm a self taught Access user with NO VB experience.
Apr 26 '07 #5
As I'm researching I found that what I'm doing is Autolookup. I am bypassing using a query, but the results are the same.
Apr 26 '07 #6
I get what you want, but until I understand how you're getting that error message I can't tell you how to do it. I get that it's not DLookup(), but what is it?
I'm doing an Autolookup between the joined tables.

Good news! Your comment of Dlookup allowed me to do a validation on the student ID field and send a nice message that my user will understand when a student ID is not in the District table.

Is there a way to launch an event after this validation to open Form2 so they can add the student data and return to Form1?
Apr 26 '07 #7
NeoPa
32,556 Expert Mod 16PB
I'll have to get to this tomorrow now probably but :
  1. The SQL you posted looks all wrong to me. I can't see how it can work at all. Did you Copy / Paste it in?
  2. I'm glad the DLookup() bit has helped.
  3. You seem to be going off at a tangent before your basic issue is resolved. That is a recipe for confusion (Mine if not yours).
Apr 26 '07 #8
I'll have to get to this tomorrow now probably but :
  1. The SQL you posted looks all wrong to me. I can't see how it can work at all. Did you Copy / Paste it in?
  2. I'm glad the DLookup() bit has helped.
  3. You seem to be going off at a tangent before your basic issue is resolved. That is a recipe for confusion (Mine if not yours).

This is what's in the record source of my form (I did paste this). When you double click on the SQL bulder it it shows you a query with the district table and students on roster tables joined with all the fields.

Expand|Select|Wrap|Line Numbers
  1. SELECT StudentsonRosterTBL.StudentID,
  2.        DistrictTBL.First,
  3.        DistrictTBL.Last,
  4.        DistrictTBL.Grade,
  5.        StudentsonRosterTBL.RostertID
  6. FROM DistrictTBL INNER JOIN StudentsonRosterTBL
  7.   ON DistrictTBL.StudentID=StudentsonRosterTBL.StudentID;
Apr 26 '07 #9
NeoPa
32,556 Expert Mod 16PB
Notice that none of the table names have embedded spaces in this version ;)
Apr 27 '07 #10
NeoPa
32,556 Expert Mod 16PB
I should say that this does answer my question (I think) but I need to find some time later to revisit this and think it through properly.
Apr 27 '07 #11
NeoPa
32,556 Expert Mod 16PB
(Post #7)
Good news! Your comment of Dlookup allowed me to do a validation on the student ID field and send a nice message that my user will understand when a student ID is not in the District table.
from this, I'm not sure you still need an answer, but from the RecordSource query you posted, it seems that students that don't have an entry in your DistrictTBL table do not even appear on your form (at all).
Apr 27 '07 #12
from this, I'm not sure you still need an answer, but from the RecordSource query you posted, it seems that students that don't have an entry in your DistrictTBL table do not even appear on your form (at all).
Correct, it's how I want it. The user is entering student ids, that if on the district table, will display their data.

I have gotten alot further on my design. I have a Not On List event that catches when not on the district table. I have it launching my Add Student form passing the student id for the user to keyin the student data into the district table and returning to my original form.

My current problem is that if they neglect to keyin the student data, my if null clause is not working when it returns to the original form. It works if they use the escape key to exit.

I'm guessing that since I'm passing the student id, it's added automatically. How do I handle this?.

I've pasted my NOT on List code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub StudentID_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 Student.
  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 Add Student Form in data entry
  16.         ' mode as a dialog form, passing the new Student ID in
  17.         ' NewData to the OpenForm method's OpenArgs argument. The
  18.         ' OpenArgs argument is used in Add Student form's Form_Load event
  19.         ' procedure.
  20.         DoCmd.OpenForm "01 add student ", , , , acAdd, acDialog, NewData
  21.     End If
  22.  
  23.     ' Look for the student the user created in the add student form.
  24.  
  25.     Result = DLookup("studentid", "districtTbl", NewData)
  26.  
  27.     If IsNull(Result) Then
  28.         ' If the student was not created, set the Response argument
  29.         ' to suppress an error message and undo changes.
  30.         Response = acDataErrContinue
  31.         ' Display a customized message.
  32.         MsgBox "Please try again!"
  33.     Else
  34.         ' If the student was created, set the Response argument to
  35.         ' indicate that new data is being added.
  36.         Response = acDataErrAdded
  37.     End If
  38. End Sub
Apr 27 '07 #13
NeoPa
32,556 Expert Mod 16PB
  1. Please remember to enclose your code in the 'Code' tags and lay it out so that it's readable if you expect us to go through it for you. A bunch of code formatted as text is really not intelligible.
  2. VBA has built-in constants for <CR> (vbCR), <LF> (vbLF) & <CR><LF> (vbCRLF) for your use.
  3. Can you explain more clearly the circumstances under which you have problems. If you have a ListBox or ComboBox on your form we need to know about it and the details of what's in it etc.
  4. Do you know how to trace through the VBA code in debug mode?
Apr 27 '07 #14
NeoPa
32,556 Expert Mod 16PB
BTW well done on the progress you've made already. Clearly not someone who needs your hand held at every step :)
Apr 27 '07 #15
  1. Please remember to enclose your code in the 'Code' tags and lay it out so that it's readable if you expect us to go through it for you. A bunch of code formatted as text is really not intelligible.
  2. VBA has built-in constants for <CR> (vbCR), <LF> (vbLF) & <CR><LF> (vbCRLF) for your use.
  3. Can you explain more clearly the circumstances under which you have problems. If you have a ListBox or ComboBox on your form we need to know about it and the details of what's in it etc.
  4. Do you know how to trace through the VBA code in debug mode?
All those constants are foreign to me, so I do not know how to format my code so you can read it. My apologies. :-(
Let me try to explain better.

What I now have is a Form1 that has a subform embedded in it. The subform collects [studentid ] in a combo box. The combo box is has the Limit to List = yes on the Data tab of the studentid field. If the student is in the District Table list, the asociated data displays. If not, I have an ON NOT in List Event that opens an Add Student form (passing the studentid) to add the student to the District table. My problem is that if the Add Student form is closed by the user w/o entering the data, the studentid gets added with blank data.

I THINK this is happening because I'm passing the student id to the Add Student form and it gets added on the load. I've determined that the only time it does not get added is if I hit the ESC key to exit out of the form.

The Before Update event looks like something I could use, but how?

BTW - I'm just amazed how much I've coded w/o any experience in VB. Your website is awesome!!! Thanks for the encouragement. :-)
Apr 27 '07 #16
NeoPa
32,556 Expert Mod 16PB
I'm finding your explanation quite confusing I'm afraid.
Let me look at it again later to see if a second look can help.

BTW. Displaying the code in readable format simply means to break the lines where necessary so that the reader doesn't need to scroll left and right to see what's there (See Post #9).
vbCR is a Carriage Return and is predefined in VBA so you don't need to create your own versions. Likewise vbLF is a Line Feed and vbCRLF is a Carriage Return / Line feed sequence - typically used in Windows text files etc to split one line from another.
Apr 30 '07 #17
Okay, I've resolved this initail problem. I'm going to open a new thread to look at a new issue. Thanks for your help. :-)
Apr 30 '07 #18
NeoPa
32,556 Expert Mod 16PB
I'm glad you got there Drayno - although I'm not sure I was much help with this one :(
Apr 30 '07 #19

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

Similar topics

2
by: Julia Baresch | last post by:
Hi everyone, My database has 3 data tables with chained one-to-many relationships i.e. Table1 1-->Many ->Table2 1-->Many ->Table3 I added a fourth table to hold supplemental data that also...
2
by: Galina | last post by:
Hello I have an application in MS Access 2000. I have a form, which includes a subform. The subform is based on a table, but locked for any editing. There is Edit button. When clicked, it starts a...
5
by: Sean Byrne | last post by:
We have a Microsoft Access 2000 database consisting of 20 tables covering 20 different events. In each table, there are 3 Team members, a date of the event and several unique fields for the event,...
13
by: Jan | last post by:
Hi I have a database that I use to keep track of the sales promotions that we send to companies. I normally send a mailing based on a subset of the companies in the database (found using the...
2
by: sara | last post by:
I think I don't understand combo boxes and forms - and all that I'm reading is just confusing me more. I am doing a "favor" for a non-profit organization. They take a phone call and need to...
1
by: JohnMOsborn | last post by:
I am designing an Access database that will use tab controls. Normally, you place different sets of fields on each page of the tab control – like Fields1-3 on Page 1, Fields 4-6 on Page 2, etc. In...
0
by: boardinhank | last post by:
I am interested on how best to accomplish this task. I have 3 tables that will be utilized in the matching and then one for an insert function if all the matches are successful I start with...
3
by: Jiwei06xie | last post by:
Dear Experts, As I am a beginner of Access 2000, could I ask for some help regarding the following situation? I have two tables called tblDelivery and tblStock, both having a text field...
7
by: kirkgilbert | last post by:
I am trying to do an onchange event in a form using a text field. The form is tied to a record set that is part of a repeated region. One the first record when I edit the data it works perfectly. ...
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
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: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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: 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
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?
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...

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.