Event Modules

G

Guest

Hi,
Is there a common variable name/s that field inputs are held in that can be
used from within an Event Module? I've been checking
len(trim(form!VariableName)) but it keeps returning it's overall length even
when I enter blanks, so it's not much good for checking against.

Any help gratefully appreciated.

Regards
Andy :)
 
A

Allen Browne

Note sure exactly what you are doing here, but the control that currently
has the focus is:
Me.ActiveControl
or even:
Screen.ActiveControl

Of course, it might not have a Value that can be compared to anything, e.g.
if it is a command button.
 
G

Guest

Hi Allen,
Here's my code....

Private Sub Passed_To_Change()
Dim Passed_To, Date_passed, Ldate_passed, Lpassed_To
Passed_To = Forms![Support Logs]![Passed to] & " "
Date_passed = Forms![Support Logs]![Dated Passed] & " "
Ldate_passed = Len(Date_passed)
Lpassed_To = Len(Trim(Passed_To))
If (Len([Passed_To]) > 2 And Len([Date_passed]) < 2) Then
Forms![Support Logs]![Dated Passed] = Now()
Else
If Len([Passed_To]) < 2 Then
Forms![Support Logs]![Dated Passed] = ""
End If
End If

End Sub

The first time in it works fine ie displays the date in the [Date Passed]
field, but if I blank the Passed To field value it does not clear the [Date
Passed] field. It still holds the original entry value in the string variable
[Passed To], so the Len function always returns a value > 2.

Is there a better way to do what I want?

I'm an Access novice so your help is very much appreciated.
Regards,
Andy
 
A

Allen Browne

Couple of issues here.

1. The procedure name - Passed_To_Change - suggests you have a control named
Passed_To. You also declared a variable named Passed_To. That's ambiguous,
so anything could happen. In fact, it looks like all the variables in the
Dim line might also be controls. Try removing the entire Dim line.

2. If there is nothing in the control, it is Null.
Len(Null) is Null.
Null is not true, so the Else block executes.
In the Else block, you used Another If, which again evaluates to Null.
Null is still not True, so this block does not run either.

This is error #6 in this article:
Common errors with Null
at:
http://allenbrowne.com/casu-12.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Andy Cap said:
Hi Allen,
Here's my code....

Private Sub Passed_To_Change()
Dim Passed_To, Date_passed, Ldate_passed, Lpassed_To
Passed_To = Forms![Support Logs]![Passed to] & " "
Date_passed = Forms![Support Logs]![Dated Passed] & " "
Ldate_passed = Len(Date_passed)
Lpassed_To = Len(Trim(Passed_To))
If (Len([Passed_To]) > 2 And Len([Date_passed]) < 2) Then
Forms![Support Logs]![Dated Passed] = Now()
Else
If Len([Passed_To]) < 2 Then
Forms![Support Logs]![Dated Passed] = ""
End If
End If

End Sub

The first time in it works fine ie displays the date in the [Date Passed]
field, but if I blank the Passed To field value it does not clear the
[Date
Passed] field. It still holds the original entry value in the string
variable
[Passed To], so the Len function always returns a value > 2.

Is there a better way to do what I want?

I'm an Access novice so your help is very much appreciated.
Regards,
Andy

Allen Browne said:
Note sure exactly what you are doing here, but the control that currently
has the focus is:
Me.ActiveControl
or even:
Screen.ActiveControl

Of course, it might not have a Value that can be compared to anything,
e.g.
if it is a command button.
 
G

Guest

Hi Allen,
I firstly changed the variable names inside the Change Event Procedure and
it still didn't work. So, I placed all code into the Exit Event Procedure,
also with the changed variable names. Hey presto, it works!

For some reason values don't change in the form!variables until just before
the Exit Event, so what I'd like to track down is where do the variable
changes occur. It's not that important at the moment so the Exit Precedure
will do.

It just looks good when the display field changes automatically as you enter
the values in the input form field without the need to move focus somewhere
else.

If you have any other thoughts I appreciate them, and in the mean time if I
come accross anything I'll post them in this thread aswell.

Thanks again for you help and have a good weekend.
Regards,
Andy "the access novice"


Allen Browne said:
Couple of issues here.

1. The procedure name - Passed_To_Change - suggests you have a control named
Passed_To. You also declared a variable named Passed_To. That's ambiguous,
so anything could happen. In fact, it looks like all the variables in the
Dim line might also be controls. Try removing the entire Dim line.

2. If there is nothing in the control, it is Null.
Len(Null) is Null.
Null is not true, so the Else block executes.
In the Else block, you used Another If, which again evaluates to Null.
Null is still not True, so this block does not run either.

This is error #6 in this article:
Common errors with Null
at:
http://allenbrowne.com/casu-12.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Andy Cap said:
Hi Allen,
Here's my code....

Private Sub Passed_To_Change()
Dim Passed_To, Date_passed, Ldate_passed, Lpassed_To
Passed_To = Forms![Support Logs]![Passed to] & " "
Date_passed = Forms![Support Logs]![Dated Passed] & " "
Ldate_passed = Len(Date_passed)
Lpassed_To = Len(Trim(Passed_To))
If (Len([Passed_To]) > 2 And Len([Date_passed]) < 2) Then
Forms![Support Logs]![Dated Passed] = Now()
Else
If Len([Passed_To]) < 2 Then
Forms![Support Logs]![Dated Passed] = ""
End If
End If

End Sub

The first time in it works fine ie displays the date in the [Date Passed]
field, but if I blank the Passed To field value it does not clear the
[Date
Passed] field. It still holds the original entry value in the string
variable
[Passed To], so the Len function always returns a value > 2.

Is there a better way to do what I want?

I'm an Access novice so your help is very much appreciated.
Regards,
Andy

Allen Browne said:
Note sure exactly what you are doing here, but the control that currently
has the focus is:
Me.ActiveControl
or even:
Screen.ActiveControl

Of course, it might not have a Value that can be compared to anything,
e.g.
if it is a command button.


Is there a common variable name/s that field inputs are held in that
can
be
used from within an Event Module? I've been checking
len(trim(form!VariableName)) but it keeps returning it's overall length
even
when I enter blanks, so it's not much good for checking against.
 
A

Allen Browne

Text boxes and combos have a Value property (the value currently in the
control), and a Text property (the text in the control.)

The Text is valid only when the control has focus. The Text is not converted
into the Value until you are ready to leave the control. In fact, while you
are typing, the Text might not be a valid Value at all. For example, if the
control is bound to a Date/Time field, and you are typing:
12/31/
then that's the Text (5 characters). But if you tried to tab out of the
control, Access would try to convert that into a date, and discover that it
doesn't work. The attempt to convert the Text to the Value fails, and you
get the error.

During the Change event, you must specify the Text property, because the
Value is not up to date yet.

Going back to the previous issue, I still can't make sense of the code, so I
am wondering if there is a basic misunderstanding here. Your code declared a
variable and set it to the value of the control, like this:
Dim MyVariable
MyVariable = Forms![Support Logs]![Passed to]

Okay, now the variable holds whatever value is in the text box. But the code
then does nothing with the variable. It does nothing except take up a bit of
the computer's memory. At the end of the sub, the memory is released, so no
harm is done, but I don't see the point.

There is no need to declare a variable you don't need. You can work directly
with a control, and assign a value to it without needing to Dim a variable.
For example:
If Len(Me.[Passed_To].Text) > 2 Then
Me.[Date Passed] = Date()
End If

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Andy Cap said:
Hi Allen,
I firstly changed the variable names inside the Change Event Procedure and
it still didn't work. So, I placed all code into the Exit Event Procedure,
also with the changed variable names. Hey presto, it works!

For some reason values don't change in the form!variables until just
before
the Exit Event, so what I'd like to track down is where do the variable
changes occur. It's not that important at the moment so the Exit Precedure
will do.

It just looks good when the display field changes automatically as you
enter
the values in the input form field without the need to move focus
somewhere
else.

If you have any other thoughts I appreciate them, and in the mean time if
I
come accross anything I'll post them in this thread aswell.

Thanks again for you help and have a good weekend.
Regards,
Andy "the access novice"


Allen Browne said:
Couple of issues here.

1. The procedure name - Passed_To_Change - suggests you have a control
named
Passed_To. You also declared a variable named Passed_To. That's
ambiguous,
so anything could happen. In fact, it looks like all the variables in the
Dim line might also be controls. Try removing the entire Dim line.

2. If there is nothing in the control, it is Null.
Len(Null) is Null.
Null is not true, so the Else block executes.
In the Else block, you used Another If, which again evaluates to Null.
Null is still not True, so this block does not run either.

This is error #6 in this article:
Common errors with Null
at:
http://allenbrowne.com/casu-12.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Andy Cap said:
Hi Allen,
Here's my code....

Private Sub Passed_To_Change()
Dim Passed_To, Date_passed, Ldate_passed, Lpassed_To
Passed_To = Forms![Support Logs]![Passed to] & " "
Date_passed = Forms![Support Logs]![Dated Passed] & " "
Ldate_passed = Len(Date_passed)
Lpassed_To = Len(Trim(Passed_To))
If (Len([Passed_To]) > 2 And Len([Date_passed]) < 2) Then
Forms![Support Logs]![Dated Passed] = Now()
Else
If Len([Passed_To]) < 2 Then
Forms![Support Logs]![Dated Passed] = ""
End If
End If

End Sub

The first time in it works fine ie displays the date in the [Date
Passed]
field, but if I blank the Passed To field value it does not clear the
[Date
Passed] field. It still holds the original entry value in the string
variable
[Passed To], so the Len function always returns a value > 2.

Is there a better way to do what I want?

I'm an Access novice so your help is very much appreciated.
Regards,
Andy

:

Note sure exactly what you are doing here, but the control that
currently
has the focus is:
Me.ActiveControl
or even:
Screen.ActiveControl

Of course, it might not have a Value that can be compared to anything,
e.g.
if it is a command button.


Is there a common variable name/s that field inputs are held in that
can
be
used from within an Event Module? I've been checking
len(trim(form!VariableName)) but it keeps returning it's overall
length
even
when I enter blanks, so it's not much good for checking against.
 
G

Guest

Hi Allen,
As you've seen from my code I really am a novice at this. I've removed the
redundent code out and put it all in the exit event and all is now well with
the world!

I'm a fossil from the the old fashioned school of 1st generation development
coding e.g. cobol.

Thanks for your help.
Andy
Allen Browne said:
Text boxes and combos have a Value property (the value currently in the
control), and a Text property (the text in the control.)

The Text is valid only when the control has focus. The Text is not converted
into the Value until you are ready to leave the control. In fact, while you
are typing, the Text might not be a valid Value at all. For example, if the
control is bound to a Date/Time field, and you are typing:
12/31/
then that's the Text (5 characters). But if you tried to tab out of the
control, Access would try to convert that into a date, and discover that it
doesn't work. The attempt to convert the Text to the Value fails, and you
get the error.

During the Change event, you must specify the Text property, because the
Value is not up to date yet.

Going back to the previous issue, I still can't make sense of the code, so I
am wondering if there is a basic misunderstanding here. Your code declared a
variable and set it to the value of the control, like this:
Dim MyVariable
MyVariable = Forms![Support Logs]![Passed to]

Okay, now the variable holds whatever value is in the text box. But the code
then does nothing with the variable. It does nothing except take up a bit of
the computer's memory. At the end of the sub, the memory is released, so no
harm is done, but I don't see the point.

There is no need to declare a variable you don't need. You can work directly
with a control, and assign a value to it without needing to Dim a variable.
For example:
If Len(Me.[Passed_To].Text) > 2 Then
Me.[Date Passed] = Date()
End If

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Andy Cap said:
Hi Allen,
I firstly changed the variable names inside the Change Event Procedure and
it still didn't work. So, I placed all code into the Exit Event Procedure,
also with the changed variable names. Hey presto, it works!

For some reason values don't change in the form!variables until just
before
the Exit Event, so what I'd like to track down is where do the variable
changes occur. It's not that important at the moment so the Exit Precedure
will do.

It just looks good when the display field changes automatically as you
enter
the values in the input form field without the need to move focus
somewhere
else.

If you have any other thoughts I appreciate them, and in the mean time if
I
come accross anything I'll post them in this thread aswell.

Thanks again for you help and have a good weekend.
Regards,
Andy "the access novice"


Allen Browne said:
Couple of issues here.

1. The procedure name - Passed_To_Change - suggests you have a control
named
Passed_To. You also declared a variable named Passed_To. That's
ambiguous,
so anything could happen. In fact, it looks like all the variables in the
Dim line might also be controls. Try removing the entire Dim line.

2. If there is nothing in the control, it is Null.
Len(Null) is Null.
Null is not true, so the Else block executes.
In the Else block, you used Another If, which again evaluates to Null.
Null is still not True, so this block does not run either.

This is error #6 in this article:
Common errors with Null
at:
http://allenbrowne.com/casu-12.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Hi Allen,
Here's my code....

Private Sub Passed_To_Change()
Dim Passed_To, Date_passed, Ldate_passed, Lpassed_To
Passed_To = Forms![Support Logs]![Passed to] & " "
Date_passed = Forms![Support Logs]![Dated Passed] & " "
Ldate_passed = Len(Date_passed)
Lpassed_To = Len(Trim(Passed_To))
If (Len([Passed_To]) > 2 And Len([Date_passed]) < 2) Then
Forms![Support Logs]![Dated Passed] = Now()
Else
If Len([Passed_To]) < 2 Then
Forms![Support Logs]![Dated Passed] = ""
End If
End If

End Sub

The first time in it works fine ie displays the date in the [Date
Passed]
field, but if I blank the Passed To field value it does not clear the
[Date
Passed] field. It still holds the original entry value in the string
variable
[Passed To], so the Len function always returns a value > 2.

Is there a better way to do what I want?

I'm an Access novice so your help is very much appreciated.
Regards,
Andy

:

Note sure exactly what you are doing here, but the control that
currently
has the focus is:
Me.ActiveControl
or even:
Screen.ActiveControl

Of course, it might not have a Value that can be compared to anything,
e.g.
if it is a command button.


Is there a common variable name/s that field inputs are held in that
can
be
used from within an Event Module? I've been checking
len(trim(form!VariableName)) but it keeps returning it's overall
length
even
when I enter blanks, so it's not much good for checking against.
 

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