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

Why can't this unbound control be changed?

P: n/a
Hi.

I cannot change the value of an unbound control (txtSR and txtSS) within
a sub call. I explain ... my sub (SRSS_set) takes the date (type date)
as input, and returns 2 values (type time).

Public Sub SRSS_set(varDate As Variant, _
varSR As Variant, _
varSS As Variant)

varSR = DLookup(...)
varSS = DLookup(...")

End Sub

Now, when I call this sub from the main module, the values of the 2
unbound controls don't change:

Call SRSS_set(Me!txtDate.Value, Me!txtSR.Value, Me!txtSS.Value)

However when I exchange the 2 unbound controls inside the sub call by 2
variables type variant, it works!

Call SRSS_set(Me!txtDate.Value, Test1, Test2)
Me!txtSR.Value = Test1
Me!txtSS.Value = Test2

Why does the first solution not work?

TIA

--
Georges

Nov 12 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
It is because the parametes are passed to the sub by value, not by reference.
I think it would be most efficient to pass Me to the function by
reference (declare it as "Byref ParentForm as Form") and then
dereference the two controls inside the sub.

Pavel

Georges Heinesch wrote:

Hi.

I cannot change the value of an unbound control (txtSR and txtSS) within
a sub call. I explain ... my sub (SRSS_set) takes the date (type date)
as input, and returns 2 values (type time).

Public Sub SRSS_set(varDate As Variant, _
varSR As Variant, _
varSS As Variant)

varSR = DLookup(...)
varSS = DLookup(...")

End Sub

Now, when I call this sub from the main module, the values of the 2
unbound controls don't change:

Call SRSS_set(Me!txtDate.Value, Me!txtSR.Value, Me!txtSS.Value)

However when I exchange the 2 unbound controls inside the sub call by 2
variables type variant, it works!

Call SRSS_set(Me!txtDate.Value, Test1, Test2)
Me!txtSR.Value = Test1
Me!txtSS.Value = Test2

Why does the first solution not work?

TIA

--
Georges

Nov 12 '05 #2

P: n/a
Hi.

1. ByRef is default, hence if I don't specify it, it's used. But to
doublecheck, I set it, and it still doesn't work.

2. To show that ByRef is not necessary, the second solution works [ Call
SRSS_set(Me!txtDate.Value, Test1, Test2) ]. In this case, variables are
used instead of the value of the control (first solution).

Why is this code not working when the control.value ist used?

TIA

--
Georges

Pavel Romashkin wrote:
It is because the parametes are passed to the sub by value, not by reference.
I think it would be most efficient to pass Me to the function by
reference (declare it as "Byref ParentForm as Form") and then
dereference the two controls inside the sub.

Pavel

Georges Heinesch wrote:
Hi.

I cannot change the value of an unbound control (txtSR and txtSS) within
a sub call. I explain ... my sub (SRSS_set) takes the date (type date)
as input, and returns 2 values (type time).

Public Sub SRSS_set(varDate As Variant, _
varSR As Variant, _
varSS As Variant)

varSR = DLookup(...)
varSS = DLookup(...")

End Sub

Now, when I call this sub from the main module, the values of the 2
unbound controls don't change:

Call SRSS_set(Me!txtDate.Value, Me!txtSR.Value, Me!txtSS.Value)

However when I exchange the 2 unbound controls inside the sub call by 2
variables type variant, it works!

Call SRSS_set(Me!txtDate.Value, Test1, Test2)
Me!txtSR.Value = Test1
Me!txtSS.Value = Test2

Why does the first solution not work?

TIA

--
Georges


Nov 12 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.