By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,963 Members | 904 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,963 IT Pros & Developers. It's quick & easy.

SetFocus Issue

agroover
P: 8
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
Share this Question
Share on Google+
5 Replies


Denburt
Expert 100+
P: 1,356
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
Expert 100+
P: 2,364
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

agroover
P: 8
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
Expert 100+
P: 1,356
Glad it is working, let us know if you have any more issues.
Apr 12 '07 #5

Dököll
Expert 100+
P: 2,364
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

Post your reply

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