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) -
Private Sub cboID_NotInList(NewData As String, Response As Integer)
-
Dim strMsg As String
-
Response = acDataErrContinue
-
strMsg = "The Medical Record Number'" & NewData & "' you selected is not in the list. "
-
strMsg = strMsg & "Do you want to add it?"
-
-
If MsgBox(strMsg, vbQuestion + vbYesNo, "Add New Patient?") = vbYes Then
-
-
DoCmd.GoToRecord , , acNewRec
-
[txtMEDREC] = NewData
-
[txtMEDREC].Enabled = True
-
[txtPATFNM].Enabled = True
-
[txtPATLNM].Enabled = True
-
[txtPATSEX].Enabled = True
-
txtPATLNM.SetFocus
-
cmdAddNewPtAccount.Enabled = True
-
Else
-
Response = acDataErrContinue
-
End If
-
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!
7 2344 @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: - If Len(Me!cboMRN) <> 8 Then
-
...Execute Error Code...
-
Else
-
...Proceed to data entry for new record...
-
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
@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: - Private Sub cboID_NotInList(NewData As String, Response As Integer)
-
Dim strMsg As String
-
Dim MyDB As Database
-
Dim rstEmployee As DAO.Recordset
-
-
Set MyDB = CurrentDb()
-
Set rstEmployee = MyDB.OpenRecordset("tblEmployee", dbOpenDynaset, dbAppendOnly)
-
-
strMsg = "The Medical Record Number you entered [" & NewData & "] is not in the list. "
-
strMsg = strMsg & "Do you want to add it?"
-
-
If MsgBox(strMsg, vbQuestion + vbYesNo, "Add New Patient?") = vbYes Then
-
With rstEmployee
-
.AddNew
-
![MRN] = NewData
-
![LastName] = "Blah, Blah"
-
![FirstName] = "Blah, Blah, Blah"
-
.Update
-
End With
-
Response = acDataErrAdded
-
Else
-
Response = acDataErrContinue
-
End If
-
-
rstEmployee.Close
-
Set rstEmployee = Nothing
-
End Sub
Hi Pat,
I did. I've tried to put the code in the AfterUpdate Feature but didn't work either. - Private Sub cboMRN_AfterUpdate(Cancel As Integer)
-
If Len(Me.cboMRN) <> 8 Then
-
MsgBox "The MRN must be exactly 8 digits. Enter a new MRN"
-
Cancel = True
-
cboMRN.setfocus
-
cboMRN.requery
-
End If
-
End Sub
-
Do I need to have an else and then in te else, excecute the Not in list?
thanks for your help.
bluemoon
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
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
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
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
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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.
...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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: 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: 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,...
| |