My Assistant
![]() ![]() |
|
|
Mar 4 2012, 10:02 AM
Post
#1
|
|
|
UtterAccess Guru Posts: 578 |
1. For the unbound text box qStaffNo on my form, if there's error after data validation, I've set the focus back to the unbound text box ready for user to re-enter the data; my SetFocus doesn't work, after the pop-up message is shown on the screen, the cursor has moved to the next unbounded text box instead of staying at the qStaffNo box. Why is this happening and how can I fix it?
2. I want to temporary remember the data entered in the qStaffNo as a variable to be used after the user finished entering data into the next unbound text box qOrderNo on the screen. Instead of declaring it as Dim, I tried declaring currStaffNo as Public, thinking that I'll be able to use the value later, but it doesn't work, I got an "invalid attribute in Sub or Function error", is that because my Sub is Private? What is the proper way to declare this variable so that I can use it later? Below is my code. Thank you in advance for any suggestions. CODE Private Sub qStaffNo_AfterUpdate()
Dim ScanStaffNo Dim currStaffNo As Byte ScanStaffNo = Me.qStaffNo If IsNumeric(ScanStaffNo) = False Then AutoMsg "Staff No. must be numeric only", "Invalid Staff No." Me.qStaffNo = "" Me.qStaffNo.SetFocus Exit Sub End If If IsNumeric(ScanStaffNo) = True Then If Len(ScanStaffNo) > 2 Then AutoMsg "Staff No. cannot contain more than 2 digits", "Invalid Staff No." Me.qStaffNo = "" Me.qStaffNo.SetFocus Exit Sub End If End If currStaffNo = Me.qStaffNo End Sub |
|
|
|
Mar 4 2012, 10:14 AM
Post
#2
|
|
|
Access Wiki and Forums Moderator Posts: 47,914 From: SoCal, USA |
Hi,
The focus issue might have something to do with your AutoMsg() function but we can't tell because we don't see it. To declare a variable that will be accessible to the entire form, you'll need to Dim it outside of any sub or function in the module (at the top). Also, data validation is usually best done in the BeforeUpdate event. Just my 2 cents... (IMG:style_emoticons/default/2cents.gif) |
|
|
|
Mar 4 2012, 10:28 AM
Post
#3
|
|
|
UtterAccess Ruler Posts: 2,655 |
You're using the wrong event! You need to use the BeforeUpdate event, in which you can Cancel the update, which will leave the Focus on the qStaffNo Control:
CODE Private Sub qStaffNo_BeforeUpdate(Cancel As Integer) As to question #2, why do you need to place the qStaffNo in a variable? It is still there and can be referenced while/after qOrderNo is populated. Are you trying to use the data elsewhere in the app, after the current Form is closed? And why are you Dimming the variable currStaffNo as a Byte? Sounds as if it should be an Integer.Dim ScanStaffNo Dim currStaffNo As Byte ScanStaffNo = Me.qStaffNo If IsNumeric(ScanStaffNo) = False Then AutoMsg "Staff No. must be numeric only", "Invalid Staff No." Cancel = True Me.qStaffNo = "" Exit Sub End If If IsNumeric(ScanStaffNo) = True Then If Len(ScanStaffNo) > 2 Then AutoMsg "Staff No. cannot contain more than 2 digits", "Invalid Staff No." Cancel = True Me.qStaffNo = "" Exit Sub End If End If currStaffNo = Me.qStaffNo End Sub Linq ;0)> |
|
|
|
Mar 4 2012, 10:45 PM
Post
#4
|
|
|
UtterAccess Guru Posts: 578 |
Thanks for all your valuable feedbacks.
Now I see the difference between BeforeUpdate and AfterUpdate. I'll need to write the currStaffNo to a table together with other info I collect after user enters the OrderNo in the next unbound textbox. I thought declaring as Byte instead of Integer can help to minimise the file size. I'll give it another try. |
|
|
|
Mar 5 2012, 10:54 AM
Post
#5
|
|
|
Access Wiki and Forums Moderator Posts: 47,914 From: SoCal, USA |
Hi,
(IMG:style_emoticons/default/yw.gif) Linq and I are happy to help. Good luck with your project. Let us know what happens... |
|
|
|
Mar 6 2012, 02:09 AM
Post
#6
|
|
|
UtterAccess Guru Posts: 578 |
I've got it working using the BeforeUpdate event.
After following Linq's advice, I removed the variable currStaffNo; just directly referenced it Me.qStaffNo at a later stage & managed to write the value to a separate table. Thank you again, both of you. |
|
|
|
Mar 6 2012, 10:43 AM
Post
#7
|
|
|
Access Wiki and Forums Moderator Posts: 47,914 From: SoCal, USA |
Hi,
Thanks for the update. Glad to hear you got it to work! (IMG:style_emoticons/default/thumbup.gif) |
|
|
|
![]() ![]() |
|
Go to Top · Lo-Fi Version | Time is now: 19th May 2013 - 06:51 AM |