Major issues with 'setfocus'

e2cheng

Registered User.
Local time
Today, 13:18
Joined
Dec 13, 2002
Messages
72
does anyone else have major issues with this run-time error??

Run-time error '2185':

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

I keep on getting this error unless I put property.setfocus in front of everything.. seems kind of retard and waste of code etc..

for ex.

i'm trying to enable a control when 4 fields have been entered.

Private Sub txt4_AfterUpdate()
If txt1.Text <> "" And txt2.Text <> "" And txt3.Text <> "" Then
cmdGo.Enabled = True
End If
End Sub

problem here is i get that error unless i do this...

Private Sub txt4_AfterUpdate()
txt1.setfocus
If txt1.Text <> ""then
txt2.setfocus
if txt2.Text <> "" then.....
txt3.setfocus
if txt3.Text <> "" Then
cmdGo.Enabled = True
End If
end if
end if
End Sub



one other question: is there a way in access that i can group everything together and refer to it as group1? i can group, btu can't seem to reference it.

last question: is there a way to set txtboxes as part of an array?

thanks for reading this far! thank you veyr much for any help/pointers provided!
 
Bypass the properties check..

If Not IsNull(Me.txtBox) Then
BLAH BLAH BLAH
End If


Naming a group seems to be a normalization issue. If your tables are normalized, then your data will automatically be grouped by its parent table.
 
wow!

thanx so much!

so using the isnull statement bypasses the need to reference properties i guess..

what's this whole deal with normalization.. i'm totally confused...

Thank you so much!
 
question about nulls

does that mean i can go around setting

txt1 = txt2=txt3 = null?

instead of

txt1.setfocus
txt1.text = ""
txt2.setfocus
....
 
What does you current table structure look like? Have you made any tables that are related to eachother.

For instance...
If you have a School Database

One School has many Teachers.
One Teacher has many Students.
One Student has many Exams.
One Exam has many Questions.
One Question has many possible answers.

Each of the 5 lines listed above would comprise its own seperate table. You would link each top (parent) table to its bottom (child) table by finding a common denominator and including this field in each of the two tables. That way, If your School Table has a School Named WBC (my alma mater) which has a School ID of 1, you could simply create a new record in your Teacher table with the School ID of 1. This is called a primary/foreign key relationship.
Confused Yet??

Here is some structure...
Code:
---Table 1---
tblSchool  (the parent table name)
SchoolID  (Primary Key for tblSchool: Autonumber)
SchoolName  (text field to identify the school)
SchoolPop  (number field to identify school population)

---Table 2---
tblTeacher  (the child table name)
TeacherID  (Primary Key for tblTeacher: Autonumber)
SchoolID  (Foreign Key related to tblSchool: Number (must match a SchoolID from tblSchool))
TeacherName  (text field to identify the name of a teacher)
TeacherHireDate  (date field to id the hire date of the teacher)

Can you see where this is going?
Maybe try creating something similar to this and then go to the relationships window and connect the two table on the SchoolID field from each of them.

Now open up tblSchool and notice how each new School will create a dropdown (subdatasheet) which will allow you to build multiple teachers for this school.

Congratulations, that's your first lesson on Normalization.

Good Luck..
 
wow!

thanx for the crash course! ok, i get what you're saying about the tables and how they are linked. i got a couple of those in the program..

so, let me see if this is right.. normalization is bascially the act of assigning a table a number.. or is a setting a value in each record to a random number for later use.

i was wondering about a whole bunch of boxes on a form. i'm trying to input data into one table from this one form. so i have a bunch of txtboxes for each field entry. i'm wondering if there's a way of calling them txtInput[1], txtInput[2], etc. so that if i want to disable them all, i can run a loop or something rather than going through each one and turning them off and on.

Thanx once again for your time and dedication in your responses.
 
This might be an out-of-date response, but ....

What property of a text box is the .Text property? Do you perhaps mean the .Value property?

Access is notorious for giving the wrong error message when it gets confused about whether a particular object has a particular property. I would guess this has happened to you because I have NEVER had to do what you said was required.

I.e.

Code:
If ( Len(Nz(Text1.Value,"")) > 0  ) And ( Len(Nz(Text2.Value,"")) > 0 ) And .... Then
  BigButton.Visible = True
  BigButton.Enabled = True
End If
 
No, you can't make an array of controls on a form.
But.. Here's the thing, if you've got enough time, know how, and creativity, you can do anything you want.

For instance. If you want to limit which text boxes are shown on a form, you could develop a set of rules that you use when naming your text boxes.
If you've got a group of boxes that deal with bikes, you could give yourself a naming rule that says, "All bike-related textboxes shall hereby begin with txtBike."
Now you can create a bunch of text boxes and name them..

txtBike1
txtBike2
txtBike3
txtBike(n)

Now you've created an array (sort of).

Now use a For Each Statement to loop through all of the controls on the form. Inside the For Each Statement you will want to check to see if 2 conditions exist.
1.) Is the control a text box.

2.) Does the control meet the naming criteria you have selected.
*** In the above example you would test this by testing the following...

Code:
If Left(ctl.Name,7) = "txtBike" Then

   'This is one of your array elements, so Do Stuff
Else
   'Not one of your array elements, so Do Other Stuff
End If


Here is what the entire process might look like..

Code:
Public Function checkBikeType(frm As Form)
    Dim ctl As Control, 

    ' Enumerate Controls collection.
    For Each ctl In frm.Controls
        ' Check to see if control is text box.
        If ctl.ControlType = acTextBox Then  'Meets Criteria #1
          If Left(ctl.Name,7) = "txtBike" Then  'Meets Criteria #2
             'This is one of your array elements, so Do Stuff
             ctl.Visible = False
          Else
             'Not one of your array elements, so Do Other Stuff
             ctl.Visible = True
          End If  
        End If
    Next ctl

End Function

Just a thought..

Good Luck..
 
thank you for all the help!

in regards to doc_man

the .Text property displays the text in the text box. I think it is similar to that of the .value property. ok.. i just checked it. it seems to give the same output, except i don't have to put that line of setfocus in front. SWEET! thanx for that tip!

in regards to sambo (most current)
i follow that totally. that's ingenius!! props man!

in regards to the normalization. it's the most effectove way of storing info for recovery... i think i'm gettting a bit more of it now (the basics that is.. ) thanx again!
 

Users who are viewing this thread

Back
Top Bottom