473,398 Members | 2,389 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.

SetFocus Issue

agroover
I can't seem to figure out how to get rid of the errors.

I recieve the following error when I leave the Grade.SetFocus in my code...

Microsoft Access can't move the focus to the control Grade

GRADE.SetFocus - Highlighted when I hit debug on the error message


Expand|Select|Wrap|Line Numbers
  1. Private Sub C_Click()
  2. GRADE.SetFocus
  3.  
  4. If GRADE.Text = "" Then
  5.             MsgBox "Please select a grade."
  6.             C.Locked = True
  7.         ElseIf GRADE.Text = Not Null Then
  8.         Else
  9.             C.Locked = False
  10.             C.SetFocus
  11. End If
  12. End Sub
  13.  
  14. Private Sub C_Exit(Cancel As Integer)
  15. GRADE.SetFocus
  16. C.Locked = False
  17. If Trim(GRADE.Text) = "1006" Then
  18.    If C.Value < 0.04 Or C.Value > 0.06 Then
  19.         MsgBox "Value must be between 0.04 and 0.06"
  20.         C.SetFocus
  21.     End If
  22. MN.SetFocus
  23. End If
  24. End Sub


When I remove Grade.SetFocus from my code, I get...

You can't reference a property or a method for a control unless the control has the focus

If GRADE.Text = "" Then - Highlighted when I hit debug on the error message

Expand|Select|Wrap|Line Numbers
  1. Private Sub C_Click()
  2.  
  3.  
  4. If GRADE.Text = "" Then
  5.             MsgBox "Please select a grade."
  6.             C.Locked = True
  7.         ElseIf GRADE.Text = Not Null Then
  8.         Else
  9.             C.Locked = False
  10.             C.SetFocus
  11. End If
  12. End Sub
  13.  
  14. Private Sub C_Exit(Cancel As Integer)
  15. GRADE.SetFocus
  16. C.Locked = False
  17. If Trim(GRADE.Text) = "1006" Then
  18.    If C.Value < 0.04 Or C.Value > 0.06 Then
  19.         MsgBox "Value must be between 0.04 and 0.06"
  20.         C.SetFocus
  21.     End If
  22. MN.SetFocus
  23. End If
  24. End Sub
The two Private Subs work fine seperately but I get the errors when I try and run it together.


Any help would be greatly appreciated.
Apr 11 '07 #1
5 3256
Denburt
1,356 Expert 1GB
First is the field Grade disabled or locked?

Second you should reference all your fields as such:

Me!Grade
If you feel you must then you can use the following but it usually isn't necesary.

Me!Grade.text

Adding Me! will be less confusing to MS Access and help speed it up a little. This could also solve the error your having also.
Apr 11 '07 #2
Dököll
2,364 Expert 2GB
First is the field Grade disabled or locked?

Second you should reference all your fields as such:

Me!Grade
If you feel you must then you can use the following but it usually isn't necesary.

Me!Grade.text

Adding Me! will be less confusing to MS Access and help speed it up a little. This could also solve the error your having also.
Good point, Denburt...

Also look to see if you did not accidentaly create another instance of Grade, for instance, Grade(0).Text, Grade(1).Text...
Apr 12 '07 #3
Thank you DoKoll and Denburt for your help. I finally got the code to work. Below is what I ended up using.

Once again, thank you for all your help and for replying so quickly.
It's greatly appreciated.


Expand|Select|Wrap|Line Numbers
  1. Private Sub C_Exit(Cancel As Integer)
  2.  
  3. Me!GradeID.SetFocus
  4.  
  5. If Me!GradeID.Text = "" Then
  6.             MsgBox "Please select a GRADE."
  7.             C.Locked = True
  8.     ElseIf Me!GradeID.Text = Not Null Then
  9.             C.Locked = False
  10.             C.SetFocus
  11. End If
  12.  
  13. Me!GradeID.SetFocus
  14. C.Locked = False
  15. If Me!GradeID.Text = "1006" Then
  16.    If Me!C.Value < 0.04 Or Me!C.Value > 0.06 Then
  17.         MsgBox "Carbon must be between 0.04 and 0.06"
  18.         Me!C.SetFocus
  19.     ElseIf Me!C.Value > 0.04 And Me!C.Value < 0.06 Then
  20.          MN.SetFocus
  21.     End If
  22. End If
  23.  
  24. End Sub
Apr 12 '07 #4
Denburt
1,356 Expert 1GB
Glad it is working, let us know if you have any more issues.
Apr 12 '07 #5
Dököll
2,364 Expert 2GB
Thank you DoKoll and Denburt for your help. I finally got the code to work. Below is what I ended up using.

Once again, thank you for all your help and for replying so quickly.
It's greatly appreciated.


Expand|Select|Wrap|Line Numbers
  1. Private Sub C_Exit(Cancel As Integer)
  2.  
  3. Me!GradeID.SetFocus
  4.  
  5. If Me!GradeID.Text = "" Then
  6.             MsgBox "Please select a GRADE."
  7.             C.Locked = True
  8.     ElseIf Me!GradeID.Text = Not Null Then
  9.             C.Locked = False
  10.             C.SetFocus
  11. End If
  12.  
  13. Me!GradeID.SetFocus
  14. C.Locked = False
  15. If Me!GradeID.Text = "1006" Then
  16.    If Me!C.Value < 0.04 Or Me!C.Value > 0.06 Then
  17.         MsgBox "Carbon must be between 0.04 and 0.06"
  18.         Me!C.SetFocus
  19.     ElseIf Me!C.Value > 0.04 And Me!C.Value < 0.06 Then
  20.          MN.SetFocus
  21.     End If
  22. End If
  23.  
  24. End Sub
Take care agroover!

It's a wonderful job that you are doing by the way, I'm hinting you teach or at least create the needed software to help educate. Need more people like you around.

In a bit!
Apr 14 '07 #6

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

Similar topics

4
by: Mad Scientist Jr | last post by:
i am trying to set focus to a specific control depending on the outcome of a validator control and it is not working. none of these methods are working to setfocus: 1....
8
by: Shachar | last post by:
Hi All, I need to start a new process calc for example and when ever the user click on the button the application should setfocus to the calc application. I use this code but it is NOT...
0
by: MrsLeigh | last post by:
I have a datagrid on a web page. In the footer there is a field that should be recieve the focus, either at the start or after a button is clicked to insert the row that is being added in the...
3
by: Jim Devenish | last post by:
In my application vehicles arrive and depart from a workshop. The ArrivalDate and the HandoverDate are each entered. Sometimes the person who should enter the arrival date forgets to do so. ...
12
by: Michael R | last post by:
TabCtrl --- ..............Tab1--Subform1 ..............Tab2--Subform2---TabCtrl2---Tab21 ..........................................................---Tab22...
0
by: srinivasarao yarru | last post by:
hi sir, in access 2003 how we can use the setfocuse property(we have to lostfocuse from one field with in that we have to setfocuse in same field) i am using this code but not setfocuse...
3
by: srinivasarao yarru | last post by:
hi in access 2003 how we can use the setfocuse property(we have to lostfocuse from one field with in that we have to setfocuse in same field) i am using this code but not setfocuse to same field...
8
by: freeskier | last post by:
I have been using the following code to cycle through a subform and disable all textboxes on a form. If a textbox on the form has the focus when this is run I get error "can't disable a control when...
2
by: tbeers | last post by:
I have a form for entering new aircraft in a database. The first box is for the aircraft registration number. I have afterupdate code to check to see if the new number is already used. I am using...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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.