Avatar of Derek Brown
Derek Brown
Flag for United Kingdom of Great Britain and Northern Ireland asked on

Code problem

Can anyone tell me how this

Dim SPL As Single  'Start point left
SPL = (190 * 56.7) - ((OAM * 0.5) * S)
Box1.Left = SPL

Is different from this
Box1.Left = (190 * 56.7) - ((OAM * 0.5) * S)

Second One works but the first one doesn't.  Have I got some corruption or is it something really stupid?
Microsoft Access

Avatar of undefined
Last Comment
Derek Brown

8/22/2022 - Mon

What are the values of OAM and S and how is the first one not working?
Derek Brown

OAM is a field

Dim S as Single
S = 200
OAM = 3000

The first moves the onscreen Box1 Left possition the second does not???

Wierd eh?

I am not sure what time you have there but it is bed time for me. Is it OK if I respond again tomorrow after you have had a look at this problem?
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)

What is Box1 ?

All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck

Double-check your usage, and ensure that your control name (Box1) is correct.

Using the same values for OAM and S between the two variations, the results are identical for me. (They both shift the control to the same horizontal position, with no errors).

Not sure exactly how your testing this - but of course if you run one immediately after the other without changing OAM or S, you're not going to see the box move.

To test that thought out, try setting up another box -- Box2.

Keep your first block of code the same:
Dim SPL As Single  'Start point left
SPL = (190 * 56.7) - ((OAM * 0.5) * S)
Box1.Left = SPL

Open in new window

And modify your second to work on Box2:

Box2.Left = (190 * 56.7) - ((OAM * 0.5) * S)

Open in new window

You *should* see that both boxes move to the same horizontal position.

(btw, I tested this by arbitrarily using 1 for both OAM and S)

MX has a good point, what is Box1 and where is it located?

Also, how is the code being run?
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Scott McDaniel (EE MVE )

If OAM is a field, try fully qualifying your reference to that:



Derek Brown

Private Sub NOM_AfterUpdate()
Box10.Left = SPL
Box11.Left = (190 * 56.7) - ((1 * 0.5) * 1)
End Sub
Public Sub DrawBoxes2()
Dim SPL As Single  'Start point left
SPL = (190 * 56.7) - ((1 * 0.5) * 1)
End Sub

Box10 is Blue
Box11 is red
Original PositionAfter Event
Sceenshot A is original location
B is after event where the box10 seems to have gone to the right instead of the left

even though spl is in a public sub the variable itself is private to that sub.  It is zero elsewhere.

Instead of using a sub use a function to return spl where needed.
Your help has saved me hundreds of hours of internet surfing.

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Derek Brown

I didn't know that. God help me I've only been doing this for 20 years. Self taught you know.

Thank you.