473,385 Members | 1,927 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.

force user to enter 8digits only

Hi,
I have a field call MRN. The property is text and max length is 8. In the data entry form, I have it as a combo box names cboMRN. I would like to force user to enter exactly 8 digits, if user enter less or more than 8, I won't allow user to add.

Here is my code in the "NOT IN LIST" feature. (If user enter a new MRN, it'll prompt user to add new MRN, if user enter an exiting MRN, it'll show the record info)
Expand|Select|Wrap|Line Numbers
  1. Private Sub cboID_NotInList(NewData As String, Response As Integer)
  2. Dim strMsg As String
  3. Response = acDataErrContinue
  4. strMsg = "The Medical Record Number'" & NewData & "' you selected is not in the list. "
  5.         strMsg = strMsg & "Do you want to add it?"
  6.  
  7.         If MsgBox(strMsg, vbQuestion + vbYesNo, "Add New Patient?") = vbYes Then
  8.  
  9.             DoCmd.GoToRecord , , acNewRec
  10.             [txtMEDREC] = NewData
  11.             [txtMEDREC].Enabled = True
  12.             [txtPATFNM].Enabled = True
  13.             [txtPATLNM].Enabled = True
  14.             [txtPATSEX].Enabled = True
  15.             txtPATLNM.SetFocus
  16.             cmdAddNewPtAccount.Enabled = True
  17.         Else
  18.             Response = acDataErrContinue
  19.         End If
  20. End Sub
I tried to set the INPUT MASK as =000000000 in the property of the cboMRN to force user to enter 8 digits, it works but then it unable the search in the combo box, when I type the MRN into the cboMRN box, it won't do search.

Can anyone please help?
thanks!
Dec 29 '08 #1
7 2344
patjones
931 Expert 512MB
@bluemoon9
First, are you saying that it saved the new record successfully, and then when you try to look for the new record in cboMRN, that it doesn't come up? If the new MRN isn't appearing in the combo box, there might be a problem with the manner in which the MRN is being stored in the record.

Second, another method you might want to try instead of using an input mask is to use the Len string function in VBA. For instance, in the AfterUpdate event for the combo box, you could put:

Expand|Select|Wrap|Line Numbers
  1. If Len(Me!cboMRN) <> 8 Then 
  2. ...Execute Error Code...
  3. Else
  4. ...Proceed to data entry for new record...
  5. End If
If you stick with the input mask though, just make sure that you raise an error box telling the user to input an MRN exactly eight characters long.

Let me know how this works out for you.

Pat
Dec 29 '08 #2
ADezii
8,834 Expert 8TB
@bluemoon9
You may wish to change your syntax, since you need to add the newly entered Item to the Row Source of the Combo Box, then Requery it by setting the Response Argument to acDataErrAdded, something similar to:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cboID_NotInList(NewData As String, Response As Integer)
  2. Dim strMsg As String
  3. Dim MyDB As Database
  4. Dim rstEmployee As DAO.Recordset
  5.  
  6. Set MyDB = CurrentDb()
  7. Set rstEmployee = MyDB.OpenRecordset("tblEmployee", dbOpenDynaset, dbAppendOnly)
  8.  
  9. strMsg = "The Medical Record Number you entered [" & NewData & "] is not in the list. "
  10. strMsg = strMsg & "Do you want to add it?"
  11.  
  12. If MsgBox(strMsg, vbQuestion + vbYesNo, "Add New Patient?") = vbYes Then
  13.   With rstEmployee
  14.     .AddNew
  15.       ![MRN] = NewData
  16.       ![LastName] = "Blah, Blah"
  17.       ![FirstName] = "Blah, Blah, Blah"
  18.     .Update
  19.   End With
  20.   Response = acDataErrAdded
  21. Else
  22.   Response = acDataErrContinue
  23. End If
  24.  
  25. rstEmployee.Close
  26. Set rstEmployee = Nothing
  27. End Sub
Dec 30 '08 #3
Hi Pat,
I did. I've tried to put the code in the AfterUpdate Feature but didn't work either.

Expand|Select|Wrap|Line Numbers
  1. Private Sub cboMRN_AfterUpdate(Cancel As Integer) 
  2.   If Len(Me.cboMRN) <> 8 Then 
  3.     MsgBox "The MRN must be exactly 8 digits. Enter a new MRN"
  4.     Cancel = True 
  5.     cboMRN.setfocus
  6.     cboMRN.requery
  7.   End If 
  8. End Sub 
  9.  
Do I need to have an else and then in te else, excecute the Not in list?
thanks for your help.
bluemoon
Dec 31 '08 #4
patjones
931 Expert 512MB
Hi:

Combo boxes have a NotInList event associated with them, which ADezii refers to in his post. If the user types in an eight-digit number, but it is not in the combo box list, the code in the NotInList event (in your case, code to enter a new record) will execute.

The AfterUpdate event would contain the check for eight digits, as you have written out, and I'm not sure why it isn't working. Did you breakpoint the code to make sure that it is indeed going into the AfterUpdate routine? If so, what is showing for the value of Me.cboMRN?

Pat
Dec 31 '08 #5
Hi Pat,
I beleive because in the property of the cboMRN box, I have the "Limit to List" =Yes; therefore, the code which I posted onto the AfterUpdate feature to check for the length doesn't work.

What I did was I set "Limit to List" = No, and entered some test data. It worked, the error mesage pop up when I entered the MRN which is <>8 digits, but then the code in the "Not In List" feature does not execute, I think because I set the "Limit to List"=No, this makes the "Not In List" feature doesn't work properly

any idea?

thanks for your help
bluemoon
Jan 7 '09 #6
Hi Pat,
I've found out a way to fix the problem. Instead of putting the add new MRN code in the NOT IN LIST function. I moved the code to the AFTER UPDATE and placed it after the code of checking for the MRN required length. All I did was modifying the code a bit so it'll search for the MRN in the table. It worked well.

thanks for your help

bluemoon
Jan 7 '09 #7
patjones
931 Expert 512MB
Hi:

Glad that you managed to fix your problem. That's how Access is sometimes - trial and error. And you learn a lot in the process also.

Pat
Jan 7 '09 #8

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

Similar topics

3
by: Jerry Hull | last post by:
I've got a very simple database, with a report that the user wants to be able to print for a single record immediately after entering the data. I've created a button on the data entry form that...
2
by: Andy Eshtry | last post by:
I need to validate a textbox control using the validation control so that user can enter only string (character) type not numbers I used comparevalidator and set the "Operator" property to...
4
by: ronen | last post by:
Hi, There are times when Passport users can sign in, on an ASP.NET site, without being prompted for credentials. This happens, as far as I know, when Passport accounts are stored locally (or...
1
by: Jonas | last post by:
Hi! I'm building an ASP.NET web application that needs an automatic logoff after a specified time out period, forcing the user to enter his/her Windows authentication credentials again. I use...
8
by: Keith H | last post by:
I'm looking for a way to force the user to re-authenticate with their Windows username/password/domain after clicking the submit button on an ASP.NET page. This is for an internal application. ...
5
by: annagel | last post by:
I am looking for a way to force a Tkinter window into focus on a system level. I know the force focus method should bring one window of my application into focus, but it seems I need to have some...
1
by: Mr. Novice | last post by:
When I would try to connect to a Virtual Server Host's admin page from Win2k Pro I would be prompted for credentials. Now that my employer has gone to XP IE goes straight to saying "You are not...
5
by: Proaccesspro | last post by:
Hello All, I've created a report that lists un-filled orders by age (in days). When the user clicks on the report it will ask them to input the number of days. (If the user wanted to see all...
41
by: Twayne | last post by:
Hi, How would I go about "forcing" a user from one page to another? I have a very simple random question/answer entrance requirement for an e-mail form. After 3 page views most people are...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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
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?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.