Control Validation

I am trying to add a validation to a form that I have.  To maintain unique 
course ID numbers, I have set the course ID number as primary key.  The 
instructor has the authority to create their own course number based on what 
course numbers have not already been used.  Over time, the course numbers 
expire and become available again.  But that is a seperate course number 
that is also a primary key.  Students can see the Course ID Number and 
select the course from there.  The course number is used internally to track 
what courses have been offered, when and by whom.

On the form that I am designing, I am trying to create a control that will 
validate the Course ID Number and (perhaps) give a recommendation if an 
invalid one is entered.  Essentially, the validation rule would compare the 
requested number with a query of currently used Course ID Numbers.  If the 
rule finds that the number already exists, it would return an error and 
recommend a number (perhaps the next number in line; or one or two away from 
their desired).  I have guessed that I could add the validation as an event 
procedure for the control as an "On Exit" event.  But, how would I code the 
validation rule?

Jason Lopez 


0
Jason
12/19/2007 10:23:52 PM
access.forms 6864 articles. 2 followers. Follow

1 Replies
534 Views

Similar Articles

[PageSpeed] 12

Jason,

I think the Before Update event is best.

Validation code could be like this...

    If DCount("*","YourTable","[Course ID] = " & Me.Course_ID) > 0 Then
       MsgBox "Course Number " & Me.Course_ID & " has already been 
allocated!"
       Cancel = True
    End If
(assumes Course ID is a number data type)

Making a recommendation for an available number is a bit trickier.  If 
you can give specific examples of the data you have in this field, and 
what sort of considerations in the recommended alternative, then it will 
make it easier for someone to give more explicit advice.

-- 
Steve Schapel, Microsoft Access MVP

Jason Lopez wrote:
> I am trying to add a validation to a form that I have.  To maintain unique 
> course ID numbers, I have set the course ID number as primary key.  The 
> instructor has the authority to create their own course number based on what 
> course numbers have not already been used.  Over time, the course numbers 
> expire and become available again.  But that is a seperate course number 
> that is also a primary key.  Students can see the Course ID Number and 
> select the course from there.  The course number is used internally to track 
> what courses have been offered, when and by whom.
> 
> On the form that I am designing, I am trying to create a control that will 
> validate the Course ID Number and (perhaps) give a recommendation if an 
> invalid one is entered.  Essentially, the validation rule would compare the 
> requested number with a query of currently used Course ID Numbers.  If the 
> rule finds that the number already exists, it would return an error and 
> recommend a number (perhaps the next number in line; or one or two away from 
> their desired).  I have guessed that I could add the validation as an event 
> procedure for the control as an "On Exit" event.  But, how would I code the 
> validation rule?
> 
> Jason Lopez 
> 
> 
0
Steve
12/19/2007 10:51:03 PM
Reply:

Similar Artilces:

Windows 7 Ultimate Office 2003 Valid Key Reported Invalid
I have just bought a new Dell system with Windows 7 Ultimate installed. I have a full install CD of Office 2003. When I try to install it I get an invalid key message even though the key is correct. I have re-verified the key through using Belarc on my old computer, and I have tried copying the files to disk and installing from there. There is no doubt the key is valid. Obviously, there is something system-wise that is causing this not to work. Is this an OEM or Home Use copy of Office 2003? -- Milly Staples [MVP - Outlook] Post all replies to the group to keep the d...

why won't word 2007 release control of a .rtf file after exiting w
I AM HAVING TROUBLE WITH ACCESS TO RICH TEXT FILES BY PROGRAMS OTHER THAN WORD------ AFTER THE FILE OPEN IN WORD IS CLOSED AND EVEN AFTER WORD HAS BEEN SHUT DOWN (EXITED) ---------- I GET THE ERROR MESSAGE THAT THE FILE IS "IN USE" BY WORD WHEN (FOR EXAMPLE) AN ATTEMPT IS MADE TO DELETE IT ---- SOMETIMES WHEN RE-OPENING THE FILE AFTER RE-STARTING WORD THE FILE CANNOT BE SAVED BECAUSE IT IS IN "READ ONLY" MODE ------- AFTER MUCH FIDDLING AROUND I FINALLY MANAGED TO DELETE THE PROBLEM FILE ONLY TO HAVE THE SAME PROBLEM RETURN WITH A DIFFERNT FILE ----- WORD 200...

RE: Control
Can some one point me right direction to achive this following. Need to dispaly a data in a table format. some of the column data may have to display a image/icon based on a value from the table (1 :- Red color icon, 2:-yellow color icon...) Once the data is loaded and displayed on the format , able to search particular row by column index and update the values including the images(change different image). I tried with Listview control, with the report view I am not able to search row and update the columns with the List vew I am not able to show the image/icon. do not want to use ...

bound control or inbound control
Hi Katherine, There are differences between using bound versus unbound controls. Where on the form do you want to use an unbound control? Jeanette Cunningham "Katherine" <Katherine@discussions.microsoft.com> wrote in message news:23BBC192-0A74-4B9F-9513-5E5923A76658@microsoft.com... > ...

MSCRM login and the Users Control Panel
Is anyone aware of any way that the settings stored under Control Panel - Users - Password Management might interfere with the process of Single Sign On into MSCRM? It seemed to have somehow cached someones login and prevented logging in as the logged in user, until cached credentials had been "deleted". However I have never seen this mentioned as being relevant. I am not too sure what the architecture model is there, but it appears to be a single domain. If this area has any relevance, it would be useful to know....thanks ...

osetup.dll digital signature does not validate or is not present
When I click on the setup icon on the disk I receive the following error message: E:\proplus.ww\osetup.dll digital signature does not validate or is not present. Any suggestions? Disc is corrupt. Get a new disc to install office "Janine" wrote: > When I click on the setup icon on the disk I receive the following error > message: E:\proplus.ww\osetup.dll digital signature does not validate or is > not present. Any suggestions? > "Sudhi" wrote: > Disc is corrupt. Get a new disc to install office > > "Janine" wro...

Adding a control variable
Hello all, Under VC++ 7.1, I've added a checkbox to a dialog. Using the dialog editor, I am not trying to add a control variable for this check box. However, when I right-click on the check box and select "Add Variable", the resulting wizard dialog does not allow me to select "Control Variable" (it is grayed out). What do I need to do to get a control variable for this check box added to my class? Thanks, Dave I've never seen that before - are you able to duplicate this problem with other projects too? -- Regards, Nish [VC++ MVP] "Dave" <bett...

Releasing memory after creating OCX control
Hi, I try to create an instance of an activex control in my MFC dialog based app. Though my application works with out any error, if i check the memory after calling "delete pMyControl" it keeps on occupying the same memory it occupied when the control was alive. Could anyone help me where I am missing to clear the memory? Thank you. My Code here ---------------m_pxWmp= new CWMPPlayer4();if( m_pxWmp->Create("replay", WS_CHILD | WS_BORDER | WS_VISIBLE , CRect(100, 100,320,240), this, 2)){ m_replay = true; m_pxWmp->SetUrl("C:\\video.avi"); m_pxWmp->Set...

Spam control - MS Outlook
Hi! I am using MS Outlook 2000 and use 2 profiles. I recently installed a firewall package (Fsecure = Telia S�ker Surf), including Spam control. After install, MSO hangs and I cannot change to the other profile (if I not removed MSO by ctrl/alt/del) Somebody want to comment this? /Sven-Erik Intergrated AV/Spam is the cause of frequent issues in Outlook Is the FSecure you installed compatible with this old version of Outlook? "Storfille" <storfille@ebrev.net> wrote in message news:b1Ixm.11987$U5.164765@newsb.telia.net... > Hi! > > I am using MS Outlook 200...

stock control system
trying to see up a 'basic stock control sytem' for a warehouse that contains building materials. -- Thank you. You can use multiple ways of doing, there's 3 ways to come to m head... 1) Use a worksheet as database an save all the information on the cell of that worksheet using some macros to access it and handle. 2) You might want to use Access instead of Excel, I think would b easier to handle the database portion and you still have the Macro available. 3) You can use VB with an Access to create an application -- fanay ------------------------------------------------------...

Creating dialog controls at run-time
I've been researching how to do this, but whenever I try what other people do, I get very bad results. But my challenge doesn't end there. The number of controls I want to create is only known at run-time. The problems I face are manifold: 1. The code most people use fails badly. Not only is the font unconventionally big, but when I click the checkbox I create, the whole dialog disappears. If that's not enough, the pointer to the control is NULL when the dialog's destructor is called, so I can't delete the instance, and get a memory leak message when the program ends: CADi...

what control can display characters from txt files in a dialog?
I want to read lines from txt files and display them on a dialog.I wonder which control can be put into the dialog to hold the characters from txt? Something like :- while(m_file.ReadString(tmpstr)) { str += tmpstr; } m_edit.SetWindowText(str); -- Regards, Nish [VC++ MVP] "liao_xf" <sclxf@sina.com> wrote in message news:001401c3652f$177b9830$a001280a@phx.gbl... > Thanks first! > I know that Edit control can receive and edit input. > and I know the filestdio can read lines from txt. > but can you tell me how to attatch the lines to the edit? > Thanks!...

MDI support in ATL composite control
Hi, I have components created in ATL. The components are ATL composite controls. Entire work has been done till now using ATL, however I now need to give MDI type of work area (based o doc-view architecture) within the control. I have class derived from CMDIFrameWnd. However when I try to initialize instance of this class by calling "Create" method of CFrameWnd (base class in CMDIFrameWnd), I get error and creation fails. Tracing the code, I found that base class create method calls "AfxGetInstanceHandle" to get handle to the DLL. Now since this is ATL Composite control, ...

validation 05-05-10
hi, I have a workbook with 2 sheets. In one sheet I have a calender and other sheet just list of names. what i want to do is: In the calender sheet if i have a name under a date and when i enter that date beside that name in the sheet of name list, i want to have a message saying that he/she is on vacation. For eg: In calender sheet a1&b1(merge 2 cells) (date-05-05-2010) a2-ganga b2-ravi In name list sheet a1-ganga- if i enter 05-05-2010 then the msg should say ganga is on vacation a2-ravi-if i enter 05-05-2010 then the msg should say ravi is on vacation Thank...

View Filtering and Access Controls for Business Units
I am trying to implement MS-CRM for my company. We have multiple Business Units . I need to give views to each Business Units so that they see only their own Contacts/Accounts/Opp lists. How do I accomplish this ? Also, If I gave inter business unit acesses , how do I make sure that the one business unit users can not modify any fields on other's Business Unit's records ? Thanks in advance for any help, Kishore This is quite easy to do with CRM. Assuming you have already created your Business Units in CRM, you can view a security role within one of the Business Units and a...

Tab Control Problems
I previously worked in VC++ 6.0, and have several applications that have either custom shadebox controls, or tab controls or group boxes. In all cases, when I moved the applications over to VS.NET 2003, everything was fine, except in the resource editor, I cannot see any of the controls that have been overlayed on a tab control, or a custom shadebox control and in some cases group boxes. I can tab to them and see the outline, but I cannot see the actual controls. If I drag a new control onto the tab control, I can see the control, but once it is saved, I can no longer access the cont...

FindRecord Control Button
i built a find record control button so a user can type in the form number and go there but it only searches the field that the cursor is in and the form # is not on the tab order(purposely). How can i specify where the find record function searches? thanks Ryan, usually people use an unbound combo box or an unbound text box for searching. There is a sample download with code of a search form at http://www.allenbrowne.com/ser-62.html If you need help to get it working, post back. You can also use the wizard to put a combo for searching on your form. On the form in design view, click the...

Controls coordinates
Hi everyone, Could somebody give me a simple example of getting a controls coordinates and then using them to put the control back where it was. So basicaly the control hasn't moved. Here's what I'm doing: m_cQuality.GetWindowRect(&qualityRC); ClientToScreen(&qualityRC); // int temp=qualityRC.Height(); // qualityRC.top=unyteRC.bottom-temp; // qualityRC.right=qualityRC.Width(); // qualityRC.left=0; // qualityRC.bottom=qualityRC.top+temp; // m_cQuality.MoveWindow(&qualityRC); m_cQuality.SetWindowPos(this, qualityRC.left, qualityRC.top, qualityRC.Width(), qualityRC.He...

User Form Data Validation
How, Please could someone point me to a good tutorial on data validation for user forms?. I have a workbook that uses the INDIRECT method to restrict options dependant on the first selection. I want to create a user form for data entry, if I use the Excel data form from the menu bar, the data validation is not carried across. A url to advice would be great, Thanks, Mickey Are you using a combobox on that userform? Instead of using =indirect() in the userform, I just used code to point at that other range. I put two comboboxes and two commmand buttons (ok/cancel) on a userform. Th...

User Control to Control Other User Control
Has anyone here created a control that controlled the content of other controls? I have my own custom ad control (for displaying space ads). I may have several on a page. What I'd like it to create another control that could determine how many instances of the first control existed on the current page, build a list of ads, and then set each control to show a particular ad. Is this practical? Suggestions? Thanks. Jonathan "Jonathan Wood" <jwood@softcircuits.com> wrote in message news:uQ5stZRnKHA.1552@TK2MSFTNGP05.phx.gbl... > Has anyone...

Controlling drawing objects in Excel . . .
i m trying to do the following. 1) i draw 10 circles, 10 rectangles and 10 ellipses (all are scattering here & there) in excel. 2) i would like to change all the sizes of circles with minimum steps. [Is it possible to control in such a way that a circle is drawn as a master one, and that circle will be copied and copied until required number. When we want to change something to all circles, we will change the master circle, and all other circles will be automatically changed.] If someone knows, kindly explain to me. Thanks & Have a nice day!!! Thaw Htin Oo. Thaw, (Oo?) One...

Need more than 1208 controls per sheet
Hi, Does anyone know how to go around the limitation of MS Excel, which doesn't let the user, through automation, to create more than 1208 controls (checkboxes, buttons, or combination of two for example) on one sheet?? Thanks much! -- mowali ------------------------------------------------------------------------ mowali's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=20886 View this thread: http://www.excelforum.com/showthread.php?threadid=491476 I don't know whether it is possible to overcome the limit, but I would not use a worksheet where the ...

MFC Table control or similar control
Hi, I have a MFC dialog database application that returns data which i then put into an excel spreadsheet and display onscreen. Due to license issues i would like to write the data to a user defined control. I would like this control to have a similar tabular look like the excel spreadsheet. It should also have the option on control to print out what data is in the control. I would also like to be able to put a bitmap on the control (Showing a logo). Can anyone give me advice on how what control(s) i should use to accomplish this? Thanks In Advance Macca You could buy a third party ...

Unprotection For ActiveX Control
I have a protected sheet but would like others to manipulate Spin Buttons (ActiveX variety) to change some of the data. But if the sheet is protected I can't use the spin buttons even when the cells to be manipulated are unprotected AND the spin buttons are unlocked. Is there ANY way to get around this without having to unprotect the entire sheet every time I use the spin buttons?? Thanks, --Abe Do you have a linkedcell? Is that cell locked? Can you unlock that linkedcell? You could put the linked cell on another sheet (or even in an unlocked hidden cell (hidden column or h...

Metrics are not available
Hi everyone, I get the following error message appear on my homepage when logging into GP9.0: "Metrics are not available because the Microsft Office Chart Control is Missing". This never appeared until we installed IE7 on all our systems, including the Citrix boxes where our users gain access to GP9.0. Following advice from a previous post I installed Office Web Components for Office XP onto the server, but it hasn't helped at all. Does anyone know a fix for this? Thanks all, T S Since the homepage is created and rendered on the individual workstation, I would look at...