Using Button to Convert Values in Form

  • Thread starter Jose Ruben Gonzalez-Baird
  • Start date
J

Jose Ruben Gonzalez-Baird

I am still trying to figure out how to convert values in a field in a form
using a button.

For instance: my button, named "GPM2CFS" will, when clicked, convert the
value in the "Drainage Rate (gpm)" field and the value in the "Drainage Rate
(cfs)" field will be updated with the converted value. The value will also
be updated in the associated Registration table.

I know how to create the button, and make certain settings for the button.
But do I tie the conversion fornmula to a macro that is then tied to the
button? Is there a way of defining the conversion formula in the macro
interface? Thanks very much for any help. Ruben
 
O

Ofer Cohen

Use code instead of Macro.
When the cursor located in the OnClick event of the button, you'll see a
button with three dots, press it and select code view.

In beteen the "Sub ...()" And "End Sub" write the code

Me.[Drainage Rate (gpm)] = Formula
 
J

Jose Ruben Gonzalez-Baird

Well I got the conversion part to work actually...except I'm still having a
few issues.

This procedure was used:
1. Create button and specified to run Maco Convert gpm to cfs on click
2. Create macro that does the following:
a. setwarmings = off
b. opentable "UIC_Registration" (where flow rates are stored)
c. openquery "upd_gpm_to_cfs" which is an update query that multiplies a
conversion factor to the value in the gpm field to obtain a value for
the cfs field.
d. close table with save = yes

this seems to have worked, but with a slight problem.

The gpm values started out as integer values, and after the macro was run,
they changed. most were close to the original value, but some were off by
more than a few decimal places. any ideas? thanks for any input. ruben.
 
J

Jose Ruben Gonzalez-Baird

Ofer,
thanks much for your message. i attempted to apply your suggestion, but
received an error message when i clicked the button: "Compile error: External
name not defined"

This is the code that was used
Private Sub Convert_gpm_to_cfs_Click()
[UIC_Registration].[Drainage_Rate (cfs)] = [UIC_Registration].[Drainage_Rate
(gpm)] * 0.00222800927
End Sub

any thoughts?

Ofer Cohen said:
Use code instead of Macro.
When the cursor located in the OnClick event of the button, you'll see a
button with three dots, press it and select code view.

In beteen the "Sub ...()" And "End Sub" write the code

Me.[Drainage Rate (gpm)] = Formula

--
Good Luck
BS"D


Jose Ruben Gonzalez-Baird said:
I am still trying to figure out how to convert values in a field in a form
using a button.

For instance: my button, named "GPM2CFS" will, when clicked, convert the
value in the "Drainage Rate (gpm)" field and the value in the "Drainage Rate
(cfs)" field will be updated with the converted value. The value will also
be updated in the associated Registration table.

I know how to create the button, and make certain settings for the button.
But do I tie the conversion fornmula to a macro that is then tied to the
button? Is there a way of defining the conversion formula in the macro
interface? Thanks very much for any help. Ruben
 
O

Ofer Cohen

Try

Private Sub Convert_gpm_to_cfs_Click()
Me.[Drainage_Rate (cfs)] = Me.[Drainage_Rate (gpm)] * 0.00222800927
End Sub
--
Good Luck
BS"D


Jose Ruben Gonzalez-Baird said:
Ofer,
thanks much for your message. i attempted to apply your suggestion, but
received an error message when i clicked the button: "Compile error: External
name not defined"

This is the code that was used
Private Sub Convert_gpm_to_cfs_Click()
[UIC_Registration].[Drainage_Rate (cfs)] = [UIC_Registration].[Drainage_Rate
(gpm)] * 0.00222800927
End Sub

any thoughts?

Ofer Cohen said:
Use code instead of Macro.
When the cursor located in the OnClick event of the button, you'll see a
button with three dots, press it and select code view.

In beteen the "Sub ...()" And "End Sub" write the code

Me.[Drainage Rate (gpm)] = Formula

--
Good Luck
BS"D


Jose Ruben Gonzalez-Baird said:
I am still trying to figure out how to convert values in a field in a form
using a button.

For instance: my button, named "GPM2CFS" will, when clicked, convert the
value in the "Drainage Rate (gpm)" field and the value in the "Drainage Rate
(cfs)" field will be updated with the converted value. The value will also
be updated in the associated Registration table.

I know how to create the button, and make certain settings for the button.
But do I tie the conversion fornmula to a macro that is then tied to the
button? Is there a way of defining the conversion formula in the macro
interface? Thanks very much for any help. Ruben
 
J

Jose Ruben Gonzalez-Baird

Perfect! I had to step off the record and come back to it but that's exactly
what I needed. Thanks VERY much! Ruben.

Ofer Cohen said:
Try

Private Sub Convert_gpm_to_cfs_Click()
Me.[Drainage_Rate (cfs)] = Me.[Drainage_Rate (gpm)] * 0.00222800927
End Sub
--
Good Luck
BS"D


Jose Ruben Gonzalez-Baird said:
Ofer,
thanks much for your message. i attempted to apply your suggestion, but
received an error message when i clicked the button: "Compile error: External
name not defined"

This is the code that was used
Private Sub Convert_gpm_to_cfs_Click()
[UIC_Registration].[Drainage_Rate (cfs)] = [UIC_Registration].[Drainage_Rate
(gpm)] * 0.00222800927
End Sub

any thoughts?

Ofer Cohen said:
Use code instead of Macro.
When the cursor located in the OnClick event of the button, you'll see a
button with three dots, press it and select code view.

In beteen the "Sub ...()" And "End Sub" write the code

Me.[Drainage Rate (gpm)] = Formula

--
Good Luck
BS"D


:

I am still trying to figure out how to convert values in a field in a form
using a button.

For instance: my button, named "GPM2CFS" will, when clicked, convert the
value in the "Drainage Rate (gpm)" field and the value in the "Drainage Rate
(cfs)" field will be updated with the converted value. The value will also
be updated in the associated Registration table.

I know how to create the button, and make certain settings for the button.
But do I tie the conversion fornmula to a macro that is then tied to the
button? Is there a way of defining the conversion formula in the macro
interface? Thanks very much for any help. Ruben
 
J

Jose Ruben Gonzalez-Baird

Perfect! I had to step off the record and come back to it to see the change,
but thats's great--exactly what I needed. Thanks VERY much! Rubem.

Ofer Cohen said:
Try

Private Sub Convert_gpm_to_cfs_Click()
Me.[Drainage_Rate (cfs)] = Me.[Drainage_Rate (gpm)] * 0.00222800927
End Sub
--
Good Luck
BS"D


Jose Ruben Gonzalez-Baird said:
Ofer,
thanks much for your message. i attempted to apply your suggestion, but
received an error message when i clicked the button: "Compile error: External
name not defined"

This is the code that was used
Private Sub Convert_gpm_to_cfs_Click()
[UIC_Registration].[Drainage_Rate (cfs)] = [UIC_Registration].[Drainage_Rate
(gpm)] * 0.00222800927
End Sub

any thoughts?

Ofer Cohen said:
Use code instead of Macro.
When the cursor located in the OnClick event of the button, you'll see a
button with three dots, press it and select code view.

In beteen the "Sub ...()" And "End Sub" write the code

Me.[Drainage Rate (gpm)] = Formula

--
Good Luck
BS"D


:

I am still trying to figure out how to convert values in a field in a form
using a button.

For instance: my button, named "GPM2CFS" will, when clicked, convert the
value in the "Drainage Rate (gpm)" field and the value in the "Drainage Rate
(cfs)" field will be updated with the converted value. The value will also
be updated in the associated Registration table.

I know how to create the button, and make certain settings for the button.
But do I tie the conversion fornmula to a macro that is then tied to the
button? Is there a way of defining the conversion formula in the macro
interface? Thanks very much for any help. Ruben
 
J

John W. Vinson

This is the code that was used
Private Sub Convert_gpm_to_cfs_Click()
[UIC_Registration].[Drainage_Rate (cfs)] = [UIC_Registration].[Drainage_Rate
(gpm)] * 0.00222800927
End Sub

any thoughts?

Change Private to Public. Private subs are available only within the same
module that contains them; if you're calling the sub from a query it needs to
be public.

John W. Vinson [MVP]
 
Top