set .Text to unbound Text Control

  • Thread starter NuBie via AccessMonster.com
  • Start date
N

NuBie via AccessMonster.com

1. i want to set the unbound text depending on what the user selects from
grpMonths (option buttons)

2. why i couldn't set unbound text, text property without set the focus to
the control. (runtime error 2115)

any other way to accomplish this?

code below:

Private Sub grpMonths_Click()
Dim strYear As String

If grpMonths.Value = 10 Or grpMonths.Value = 11 Or grpMonths.Value = 12
Then
If Format(Now(), "mmm") = "Oct" Or Format(Now(), "mmm") = "Nov" Or
Format(Now(), "mmm") = "Dec" Then
strYear = Year(Now())
Else
strYear = Year(Now()) - 1
End If
Else
strYear = Year(Now())
End If
strDate = grpMonths.Value & "/1/" & strYear

' lines below is my problem

EndDate.SetFocus
EndDate.Text = strDate

End Sub
 
D

Dirk Goldgar

NuBie via AccessMonster.com said:
1. i want to set the unbound text depending on what the user selects from
grpMonths (option buttons)

2. why i couldn't set unbound text, text property without set the focus to
the control. (runtime error 2115)

any other way to accomplish this?

code below:

Private Sub grpMonths_Click()
Dim strYear As String

If grpMonths.Value = 10 Or grpMonths.Value = 11 Or grpMonths.Value = 12
Then
If Format(Now(), "mmm") = "Oct" Or Format(Now(), "mmm") = "Nov" Or
Format(Now(), "mmm") = "Dec" Then
strYear = Year(Now())
Else
strYear = Year(Now()) - 1
End If
Else
strYear = Year(Now())
End If
strDate = grpMonths.Value & "/1/" & strYear

' lines below is my problem

EndDate.SetFocus
EndDate.Text = strDate

End Sub


In Access, unlike Visual Basic, you don't usually work with the .Text
property of controls. That property is only meaningful and accessible while
the control has the focus. Instead, you use the .Value property of the
control. The .Value property is the default property of most data controls,
so you don't have to explicitly name it, and it is available whether or not
the control has the focus.

Instead of:
EndDate.SetFocus
EndDate.Text = strDate

.... just write:

Me.EndDate = strDate
 
N

NuBie via AccessMonster.com

Thank you!!! You're God sent....

how do i mark this thread resolved? how do i rate you? how do i add
reputation?

This thread is resolved....

Dirk said:
1. i want to set the unbound text depending on what the user selects from
grpMonths (option buttons)
[quoted text clipped - 28 lines]

In Access, unlike Visual Basic, you don't usually work with the .Text
property of controls. That property is only meaningful and accessible while
the control has the focus. Instead, you use the .Value property of the
control. The .Value property is the default property of most data controls,
so you don't have to explicitly name it, and it is available whether or not
the control has the focus.

Instead of:
EndDate.SetFocus
EndDate.Text = strDate

... just write:

Me.EndDate = strDate
 
L

Linq Adams via AccessMonster.com

I'm confused by a couple of things here! The error you report, 2115, means:

"The macro or function set to the BeforeUpdate or ValidationRule property for
this field is preventing Microsoft Access from saving the data in the field."

As to the setting focus to

EndDate

before using

EndDate.Text = strDate

that's the way the .Text Property works! But, in point of fact, you shouldn't
be using the .Text Property,! This is VBA not Visual Basic! You should be
using

EndDate.Value = strDate

which doesn't require that EndDate have focus first. And since .Value is the
Default Property, you can simply use

EndDate = strDate
 
D

Dirk Goldgar

NuBie via AccessMonster.com said:
Thank you!!!

You're welcome.
how do i mark this thread resolved? how do i rate you? how do i add
reputation?

Since you're using Access Monster, I don't know. I get at this forum by
accessing the Microsoft news server directly using a mail & news client, so
I don't really know how Access Monster is set up.

Thank you, but don't worry about rating and rep for me.
 
N

NuBie via AccessMonster.com

Noted. Thanks to both of you

Linq said:
I'm confused by a couple of things here! The error you report, 2115, means:

"The macro or function set to the BeforeUpdate or ValidationRule property for
this field is preventing Microsoft Access from saving the data in the field."

As to the setting focus to

EndDate

before using

EndDate.Text = strDate

that's the way the .Text Property works! But, in point of fact, you shouldn't
be using the .Text Property,! This is VBA not Visual Basic! You should be
using

EndDate.Value = strDate

which doesn't require that EndDate have focus first. And since .Value is the
Default Property, you can simply use

EndDate = strDate
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top