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

Help with Error Handling - 2 Keyed Fields

2
Hello All,

Thanks for any info you might have.

I have an Access database that is tracking Student Grades. Part of the gig is mapping their future courses [CourseID].

What I'm trying to do is either narrow down a Combobox as courses are selected (remove a course if it has already been entered), or stay away from the Access built-in error messages.

One student can have multiple terms [ProgramID], and multiple courses per term [CourseID]. These two fields make up the Key on the Record source for OOSMap table.

I have a Main form (OOSMain) - a subform (OOSMap) - and a subform off OOSMap (OOSMapSubForm).

The code I have works for the [CourseID] but doesn't when the [ProgramID] is factored in. It won't let me enter a [CourseID] for a second map (required) if it exists in the first map (ignores the [ProgramID] part of the key).

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2.  
  3.     DoCmd.SetWarnings False
  4.  
  5.     Dim Answer As Variant
  6.     Answer = DLookup("[CourseID]", "OOSMap", "[CourseID] = '" & Me.CourseID & "'")
  7.     If Not IsNull(Answer) Then
  8.     MsgBox "Course already exists in this Map," & vbCrLf & "Please select another course", vbCritical + vbOKOnly + vbDefaultButton1, "Duplicate"
  9.  
  10.  Cancel = True
  11.  Me.CourseID.Undo
  12.  
  13.     DoCmd.SetWarnings True
  14.  
  15.  Else:
  16.  End If
  17. End Sub
Thanks for any suggestions... and yes... I am not a programmer.
Aug 26 '18 #1
3 1114
twinnyfo
3,653 Expert Mod 2GB
JetB,

Welcome to Bytes!

First, it looks like your CourseID is a text value--or at least you are referring to it as a text value in your code (Line 6). If it is a text value that is fine, but usually "IDs" in database jargon is for a long integer (numeric) value. If this is the case, then you would want to remove the single quotes fro your DLookup() statement.

However, you don't provide enough information for us to troubleshoot your real problem:

JetB:
The code I have works for the [CourseID] but doesn't when the [ProgramID] is factored in. It won't let me enter a [CourseID] for a second map (required) if it exists in the first map (ignores the [ProgramID] part of the key).
It appears you have given us the code that works? If this is the case, there is nothing to troubleshoot. However, if you provide the code you have been working with that does not work, we will be glad to take a look at it and try to troubleshoot the problem areas.

Hope this hepps!
Aug 27 '18 #2
PhilOfWalton
1,430 Expert 1GB
There is a much more elegant way of handling your problem, but without seeing detailed table structures and your form, it will not be easy to give further guidance. An Image of your relationship pane and form would help.

Basically the method shows only the courses still available in the combo box, so you don't need to have a Msgbox about "the course already having been allocated", as it just doesn't show up.

Basically you create a query that shows which courses the student is enrolled for in that term, and a second query that lists all the coursed available that aren't in the first query.

Here is an example of query used as the RowSource of a combo box for seat allocation, oddly enough for a school application.

Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCTROW tblSeat.SeatID, tblSeat.Seat AS Unallocatedt
  2. FROM tblSeat
  3. WHERE (((tblSeat.SeatID) 
  4. Not In 
  5. (SELECT tblInstr.InstrSeatID FROM tblSeat 
  6. INNER JOIN (tblHRm INNER JOIN (tblStudents 
  7. INNER JOIN tblInstr ON tblStudents.StudentID = tblInstr.InstrStudentID) 
  8. ON tblHRm.HRmSectionID = tblStudents.StudentHRmSectionID) 
  9. ON tblSeat.SeatID = tblInstr.InstrSeatID 
  10. WHERE (((tblInstr.InstrDate)=Format([Forms]![frmDailyInstruction]![txtTheDate],"mmm/dd/yyyy")) 
  11. AND ((tblHRm.HRmABPeriodID)=[forms]![frmDailyInstruction]![cboABPeriodID])) ORDER BY tblInstr.InstrSeatID )))
  12. ORDER BY tblSeat.SeatID;
  13.  
The critical thing is the "Not In(" statement

Hope that gets you started

Phil
Aug 27 '18 #3
JetB
2
Thanks a lot, I thought an Not In or Union statement would work better. I'll give it shot ASAP.
Aug 28 '18 #4

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

Similar topics

1
by: monika | last post by:
hi ... I want to do error handling in my application. I have made a complete application. but when I encounter errors (like mentioned below) I want to do error handling. how can I do it? I...
1
by: Bill S. | last post by:
Hi, I a stored procedure that inserts a record into a table as below. The insert works OK, but if the insert violates a unique indewx constraint on one of the columns, the proc terminates...
2
by: CSDunn | last post by:
Hello, I need some assistance with error handling in an Access 2003 Project form. The project is has a data source connection to a SQL Server 2000 database. The main form is named...
7
by: Spacen Jasset | last post by:
The main two desirable things I feel error handling should provide are these: 1) Debugging and diagnostic aid 2) User feedback One method that is used a fair amount it to 'say' that all...
9
by: Gustaf | last post by:
I'm confused about structured error handling. The following piece of code is a simplification of a class library I'm working on. It works, and it does what I want, but I'm still not convinced that...
10
by: Anthony England | last post by:
(sorry for the likely repost, but it is still not showing on my news server and after that much typing, I don't want to lose it) I am considering general error handling routines and have...
1
by: GS | last post by:
Any points of what would be the good error handling design for application? User error handling in Application_OnError and throw() new errors on conditions through the code? I'd like utlimiately to...
5
by: csgraham74 | last post by:
Hi guys, Basically i have been developing in dotnet for a couple of years but ive had a few issues in regards to error handling. For example - I have a class that i call passing in a stored...
7
by: iritchie | last post by:
Hello all, I am trying to write a script which breaks down a single address field into individual fields, with char(10) or a carriage return as the delimiter. "empltable" is the table I am...
19
by: MysticElaine | last post by:
Hello, I have a main Case form, that when I click a button, a new Client form opens. On the Client form, I have 3 text boxes that users use to create a new client, first name, last name, and date...
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
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: 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
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
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
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,...
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.