custom format metric/imperial

D

Doug_E_FL

I am storing all my lengths in mm but allowing to input in either metric or
imperial.

I am able to create a field in a query that calls a function to convert this
which works fine however this field is not updateable. I am using this on a
continuous form.

The imperial number is input as ex. 1201.15 for 12'-1 15/16 and stored as
3706.8
metric is in mm

Any help would be appreciated
 
F

Fred

I noticed that nobody answered. You never really pointed out what your
specific question or problem is.....

- An un-updatable query /form? If so a quick first thing to check is
that one side of your link is a Primary Key (and thus also unique)

- Need help with the math or code?

Then we'd need more infr relevant to taht particular question.
 
D

Doug_E_FL

y, i didn't quite ask a question. Perhaps this will describe it better.

I want to store a number in mm only but allow and show for input in either
mm or imperial in a form.

If there was a way to call a function in the property format in a form I
would be able to convert it to show correctly and perhaps use afterupdate to
convert the number back to mm for storage? perhaps there is a way to
override the format property via a class module?

I am able to create a field in a query that will show the number correctly
however this is not an updateble field. So when I use it on a continuous form
I can't use it for input.

thanks
 
J

James A. Fortune

Doug_E_FL said:
y, i didn't quite ask a question. Perhaps this will describe it better.

I want to store a number in mm only but allow and show for input in either
mm or imperial in a form.

If there was a way to call a function in the property format in a form I
would be able to convert it to show correctly and perhaps use afterupdate to
convert the number back to mm for storage? perhaps there is a way to
override the format property via a class module?

I am able to create a field in a query that will show the number correctly
however this is not an updateble field. So when I use it on a continuous form
I can't use it for input.

thanks

:

<air code idea> Perhaps have a bound form with an unbound control for
your measurement and two unbound toggle buttons that untoggle each other
for metric/imperial. Have the toggle default to the way the number is
stored in the table. In the AfterUpdate event of the unbound textbox,
have the code look at the toggle values and decide whether or not to
apply a conversion multiplier before saving the new value to the
invisible bound textbox. Maybe the Form's Current event can put the
invisible bound measurement into the unbound textbox. </air code idea>

Something like:

'Begin code behind form
Option Compare Database
Option Explicit

Private Sub Form_Current()
txtUnbound.Value = txtMeasurement.Value
End Sub

Private Sub tglImperial_Click()
tglImperial.Value = -1
tglMetric.Value = 0
End Sub

Private Sub tglMetric_Click()
tglMetric.Value = -1
tglImperial.Value = 0
End Sub

Private Sub txtUnbound_AfterUpdate()
If tglImperial.Value = -1 Then
txtMeasurement.Value = txtUnbound.Value
Else
txtMeasurement.Value = txtUnbound.Value / 2.2
End If
Me.Dirty = False
End Sub
'End code behind form

The toggle indicates whether the next value input is Imperial or Metric.
The code is for Imperial values stored in the table. Your conversion
formula is a little more complicated, but the same principle should
apply. You can also use the Current event to populate two unbound
properly labeled textboxes if you want to show/edit both sets of units
simultaneously and dump the toggle buttons.

James A. Fortune
(e-mail address removed)
 

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