سؤال

In Access 2010, I've built a calendar Form that I want to be able to display who is off in a given month.

Each box of the calendar obviously represents a different day. I've got a table called "Separated" set up that ultimately stores the associate name and the date they are off -- one day per record.

Here's what I've done so far to try to test it on just one of the boxes (representing a day):

Private Function fillDays()
    Dim rsNames As DAO.Recordset

    Set rsNames = CurrentDb.OpenRecordset("SELECT * FROM Separated")
    If Not rsNames.EOF Then
        b0.Text = rsNames![Associate]
    End If
    Set rsNames = Nothing
End Function

I get the following debug note: "Run-Time Error '2185"
"You can't reference a property or method for a control unless the control has the focus."

The debugger highlights the line with "b0.text = rsNames![Associate]

Is there some whay that I need to reference an index number from my "Separated" table?... or perhaps using a query method of some sort would be more effecient.

هل كانت مفيدة؟

المحلول

Assuming b0 is a textbox, the error you are getting is due to the fact that you can't use it's Text property when said textbox hasn't got the focus.

As stated in MSDN, «While the control has the focus, the Text property contains the text data currently in the control; the Value property contains the last saved data for the control. When you move the focus to another control, the control's data is updated, and the Value property is set to this new value. The Text property setting is then unavailable until the control gets the focus again» (emphasis mine).

Try using Value (help here) instead:

b0.Value = rsNames![Associate]
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top