Run Module from macro problem (1 Viewer)

Poppy

Registered User.
Local time
Today, 03:19
Joined
Feb 22, 2005
Messages
18
Hi Experts

I've managed with a lot of help to get my program to work, however when I try to run the module from a macro I get problems.

When I'm in the code window of the module and click run, everything is fine, however when I use RunCommand and run the Command "Run". it does not run.

These are my steps: OpenForm, OpenModule, RunCommand and Close. What am I doing wrong or forgetting. :confused:

Thanx for all the help

Kind Regards
 

M8KWR

Registered User.
Local time
Today, 01:19
Joined
Sep 30, 2004
Messages
146
what are you running from the module.

Why don't you set the module to run when the form is opened, and then at the end of the code, close the form.

If you could paste the module code etc that may help...
 

Poppy

Registered User.
Local time
Today, 03:19
Joined
Feb 22, 2005
Messages
18
Hi

This is the code in the module. How would I set the module to run when the button is clicked?

Code:
Option Compare Database
Option Explicit

Private Sub Button5_Click()

Dim prevMonth As Integer
Dim curMonth As Integer
Dim prevYear As Integer
Dim curYear As Integer
Dim CurRecordMonth As Integer
Dim rst As Recordset
Dim rst2 As Recordset
Dim db As Database
Dim monthText As Variant

Set db = CurrentDb

'fill an array with the text for months names
monthText = Array("", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")

' find previous and current Year and month. If current month = jan then go back to Dec of the year before
    curMonth = Month(Date)
    curYear = Year(Date)
    prevYear = Year(Date)
    prevMonth = Month(Date) - 1
    
    If prevMonth = 0 Then
        prevMonth = 12
        prevYear = prevYear - 1
    End If
    
' count number of existing records for current year and month
'    If DCount("Month", "TTransactions", "month = '" & monthText(curMonth) & "' and year = " & curYear) = 0 Then

  If DCount("Month", "tTransactions", "month = " & curMonth & " and year = " & curYear) < 2 Then
        'if zero current month and year does not exist in table
        ' open table and find last months record
        Set rst = db.OpenRecordset("tTransactions", dbOpenDynaset)
        rst.FindFirst "month = " & prevMonth & " and year = " & prevYear
        ' open table again to write a new record
        Set rst2 = db.OpenRecordset("tTransactions", dbOpenDynaset)
        Do Until rst.NoMatch  ' loop through all records meeting the criteria
            rst2.AddNew
                rst2![TelNo] = rst![TelNo]
                rst2!Year = curYear
                rst2!Month = curMonth
                rst2!Rental = rst!Rental
                rst2![fees] = rst![fees]
                rst2![Vat] = rst![Vat]
            rst2.Update
            rst.FindNext "month = " & prevMonth & " and year = " & prevYear
        Loop
        rst.Close
        rst2.Close
        Set rst = Nothing
        Set rst2 = Nothing
    End If
    Set db = Nothing

End Sub

This is the situation: I have a form with Button 5. When Button is clicked open Macro1 and in macro1 I set those commands eg. RunCommand.
 

Poppy

Registered User.
Local time
Today, 03:19
Joined
Feb 22, 2005
Messages
18
Thanx

Solved my problem.

Kind Regards
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 20:19
Joined
Feb 19, 2002
Messages
43,768
For those of you who might read this later, you cannot "run" a module. You "run" a proceture.
 

Users who are viewing this thread

Top Bottom