Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Correct Format? 2

Status
Not open for further replies.

Kurt6905

Technical User
Aug 21, 2006
14
0
0
US
I have a question for any VB expert out there. I have the following module written for Access 97, however, the Run button will not activate. What needs to be done to get the Run button activated? Is the program language correct? (Added information - the database is named Structural 2005. The fields Amount, Units, and Formulation are used to calculate the field Active.)

Option Compare Database
Option Explicit

docmd.set warnings false

DoCmd.RunSQL "update Structural 2005 set Active = Amount * 8.35 * Formulation * 0.01 where Units= 'GAL'"

DoCmd.RunSQL "update Structural 2005 set Active = Amount/16 * Formulation * 0.01 where Units= 'OZ'"

DoCmd.RunSQL "update Structural 2005 set Active = Amount * Formulation * 0.01 where Units= 'LBS'"

docmd.set warnings true

Thanks for any assistance.
 
If your code in the module is exactly as shown then you have executable statements (i.e. DoCmd ...) in the General Declarations section of the module. Such statements won't run in the General Declarations section. They must be within a procedure (Sub or Function) to run.
Code:
Option Compare Database
Option Explicit

[red]Public Sub DoTheUpdates()[/red]
docmd.set warnings false

DoCmd.RunSQL "update Structural 2005 set Active = Amount * 8.35 * Formulation * 0.01 where Units= 'GAL'"

DoCmd.RunSQL "update Structural 2005 set Active = Amount/16 * Formulation * 0.01 where Units= 'OZ'"

DoCmd.RunSQL "update Structural 2005 set Active = Amount * Formulation * 0.01 where Units= 'LBS'"

docmd.set warnings true
[red]End Sub[/red]
And then call [red]DoTheUpdates[/red] from where ever it makes sense to run those commands.
 
also if the table name has a space in the name you must put it in brackkets
Option Compare Database
Option Explicit

Public Sub DoTheUpdates()
docmd.set warnings false

DoCmd.RunSQL "update [Structural 2005]set Active = Amount * 8.35 * Formulation * 0.01 where Units= 'GAL'"

DoCmd.RunSQL "update [Structural 2005]set Active = Amount/16 * Formulation * 0.01 where Units= 'OZ'"

DoCmd.RunSQL "update [Structural 2005] set Active = Amount * Formulation * 0.01 where Units= 'LBS'"

docmd.set warnings true
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top