Calendar

Tumby

Registered User.
Local time
Today, 12:54
Joined
Jan 12, 2009
Messages
64
:confused:I found a calendar on this site- Inpu2000.mdb and it works fine, just what I am looking for.

The problem I have is when I copy it into my database I get the following error-
Compile error
Sub or Function not defined.

The code is as follows, with the lines highlighted being where the problem is.


Option Compare Database
Option Explicit
Private Sub cmdPrevMo_Click()

If Me!month > 1 Then
Me!month = Me!month.Column(0) - 1
Else
Me!month = 12
Me!year = Me!year - 1
End If

Call Cal([month], [year])
End Sub
Private Sub cmdNextMo_Click()
If Me!month < 12 Then
Me!month = Me!month.Column(0) + 1
Else
Me!month = 1
Me!year = Me!year + 1
End If
Call Cal([month], [year])
End Sub
Private Sub Form_Load()
Dim i As Integer, j As Integer
Dim mycontrol As Control
Dim strYear As String, nextYear As String
Dim f As Form
Dim mynum

Set f = Forms!frmCalendar

For i = 1 To 37
Forms!frmCalendar!("Text" & i).Visible = False
Forms!frmCalendar!("Day" & i).Visible = False
Next

'Set mycontrol = Me.Year
j = 1990

strYear = j

For i = 1 To 60
nextYear = j + i
strYear = strYear & ";" & nextYear
'Me.Year.AddItem j + i
Next i

Me.year.RowSource = strYear
Me!month = Format(Now, "m")
Me!year = Format(Now, "yyyy")
Call Cal([month], [year])

End Sub
Private Sub year_AfterUpdate()
Call Cal([month], [year])
End Sub
Private Sub Close_Click()
'DoCmd.Close
'DoCmd.Quit
End Sub
Private Sub Print_Click()
'Me.Visible = False
'DoCmd.OpenReport "rptCalender", acViewPreview
DoCmd.OpenForm "frmChoose"
End Sub
error-

I really would appreciate some help with this.
Thanks.
 
If you will use the CODE tags (the #) then your post would look like:
Code:
Option Compare Database
Option Explicit

Private Sub cmdPrevMo_Click()

   If Me!Month > 1 Then
      Me!Month = Me!Month.Column(0) - 1
   Else
      Me!Month = 12
      Me!Year = Me!Year - 1
   End If

   Call Cal([Month], [Year])
End Sub

Private Sub cmdNextMo_Click()
   If Me!Month < 12 Then
      Me!Month = Me!Month.Column(0) + 1
   Else
      Me!Month = 1
      Me!Year = Me!Year + 1
   End If
   Call Cal([Month], [Year])
End Sub

Private Sub Form_Load()
   Dim i As Integer, j As Integer
   Dim mycontrol As Control
   Dim strYear As String, nextYear As String
   Dim f As Form
   Dim mynum

   Set f = Forms!frmCalendar

   For i = 1 To 37
      Forms!frmCalendar!("Text" & i).Visible = False
      Forms!frmCalendar!("Day" & i).Visible = False
   Next

   'Set mycontrol = Me.Year
   j = 1990

   strYear = j

   For i = 1 To 60
      nextYear = j + i
      strYear = strYear & ";" & nextYear
      'Me.Year.AddItem j + i
   Next i

   Me.Year.RowSource = strYear
   Me!Month = Format(Now, "m")
   Me!Year = Format(Now, "yyyy")
   Call Cal([Month], [Year])

End Sub

Private Sub year_AfterUpdate()
   Call Cal([Month], [Year])
End Sub

Private Sub Close_Click()
'DoCmd.Close
'DoCmd.Quit
End Sub

Private Sub Print_Click()
'Me.Visible = False
'DoCmd.OpenReport "rptCalender", acViewPreview
   DoCmd.OpenForm "frmChoose"
End Sub
I suspect there is a standard module with the "Cal()" sub in it that was not copied.
 
Hi -

Inpu2000.mdb is the name of the database -- what is the link to the site you found it at?

I suspect there is a standard module with the "Cal()" sub in it that was not copied.

I agree. I recognize the code and could post a copy but couldn't guarantee that it hasn't been modified.

Bob
 
There was a module file which I had copied.
Where I found it?-
I searched this site for Calendars and then on page 3 under Calendar Form I found it.

After several other replies to this thread I found Oldsoftboss's reply with an updated file-
I am using Access 2002
Attached Files
zip.gif
Input2000.zip (56.7 KB, 838 views)
 
HI -

If you will use the CODE tags (the #) then your post would look like:

I'm confused.

Enclosing the code in Code Markers creates the following. Formatting is another question.

Code:
Option Compare Database
Option Explicit
Private Sub cmdPrevMo_Click()

If Me!month > 1 Then
Me!month = Me!month.Column(0) - 1
Else
Me!month = 12
Me!year = Me!year - 1
End If

Call Cal([month], [year])
End Sub
Private Sub cmdNextMo_Click()
If Me!month < 12 Then
Me!month = Me!month.Column(0) + 1
Else
Me!month = 1
Me!year = Me!year + 1
End If
Call Cal([month], [year])
End Sub
Private Sub Form_Load()
Dim i As Integer, j As Integer
Dim mycontrol As Control
Dim strYear As String, nextYear As String
Dim f As Form
Dim mynum

Set f = Forms!frmCalendar

For i = 1 To 37
Forms!frmCalendar!("Text" & i).Visible = False
Forms!frmCalendar!("Day" & i).Visible = False
Next

'Set mycontrol = Me.Year
j = 1990

strYear = j

For i = 1 To 60
nextYear = j + i
strYear = strYear & ";" & nextYear
'Me.Year.AddItem j + i
Next i

Me.year.RowSource = strYear
Me!month = Format(Now, "m")
Me!year = Format(Now, "yyyy")
Call Cal([month], [year])

End Sub
Private Sub year_AfterUpdate()
Call Cal([month], [year])
End Sub
Private Sub Close_Click()
'DoCmd.Close
'DoCmd.Quit
End Sub
Private Sub Print_Click()
'Me.Visible = False
'DoCmd.OpenReport "rptCalender", acViewPreview
DoCmd.OpenForm "frmChoose"
End Sub

Bob
 
Oops! My bad.

Had the OP copied/paste from the formatted form module, then enclosed the code in Code Markers, it comes out exactly as you described.

I was looking at what was actually posted in this thread. Sorry -- it was a dumb observation.

Bob
 
TRY AGAIN!
Please Pleasse can someone help?

I have the attached file of a really good calendar where appointements can be entered.
The problem is when I import it into my database (Access 2002) I get this
error-

Compile error
User-defined type not defined

Code:
Option Compare Database
Option Explicit
Function Cal(m, Y)
     Dim a
     Dim DayOne
     Dim gOffset
     Dim f As Form
     Dim workdate
     
     Set f = Forms!frmCalendar
     
     f!month.SetFocus
     m = f!month
     Y = f!year
     
     For a = 1 To 37
        f("Day" & a + gOffset).Visible = False
        f("Text" & a + gOffset).Visible = False
        f("date" & a + gOffset) = Null
        f("day" & a + gOffset) = Null
     Next
     
     DayOne = DateValue("1/" & m & "/" & Y)
'     DayOne = DateValue(m & "/1/" & Y)
     workdate = DayOne
     gOffset = WeekDay(DayOne) - 1
     
     For a = 1 To LenMonth(DayOne)
        f("Day" & a + gOffset).Visible = True
        f("Text" & a + gOffset).Visible = True
        f("date" & a + gOffset) = workdate
        workdate = workdate + 1
        f("day" & a + gOffset) = a
     Next
    
    Call PutInData
    
End Function
Function LenMonth(d)
    Dim start, finish
    
    start = DateValue("1/" & month(d) & "/" & year(d))
'    start = DateValue(month(d) & "/1/" & year(d))
    finish = DateAdd("m", 1, start)
    LenMonth = finish - start
End Function
Function SendToInputBox(mynum)
    Dim f As Form
    Dim g As String
    
    Set f = Forms!frmCalendar
    g = Format(f("Date" & mynum), "dddd mmmm d, yyyy")
    
    DoCmd.OpenForm "frmInputBox"
    
    With Forms!frmInputBox
        !InputDay = mynum
        !InputDate = f("Date" & mynum)
        !InputFor = g
        !original_text = f("Text" & mynum)
        !InputText = f("Text" & mynum)
        !InputText.SetFocus
    End With
    
    SendKeys "{F2}^{HOME}", False
    
End Function
[COLOR=red]Public Sub PutInData()
[/COLOR]    Dim sql As String
    Dim f As Form
    Dim [COLOR=red]db [/COLOR][COLOR=red]As DAO.Database
[/COLOR]    Dim rs As DAO.Recordset
    Dim i As Integer
    Dim myDate As Date
    
    Set f = Forms!frmCalendar
 
'Empty out the previous month
    For i = 1 To 37
        f("text" & i) = Null
        f("text" & i).BackColor = 10944511
    Next i
    
'Construct a record source for the month
    sql = "SELECT * FROM [tblInput] WHERE ((MONTH(InputDate) = " & f!month & "  AND YEAR(InputDate)= " & f!year & ")) ORDER BY InputDate;"
        
    Set db = CurrentDb()
    Set rs = db.OpenRecordset(sql, dbOpenSnapshot)
    
'Populate the calendar
    If rs.RecordCount > 0 Then
        For i = 1 To 37
            If IsDate(f("date" & i)) Then
                myDate = Format((f("date" & i)), "mm/dd/yyyy")
                rs.FindFirst "InputDate = #" & myDate & "#"
                If Not rs.NoMatch Then
                    f("text" & i) = rs!InputText
                    f("text" & i).BackColor = 12058551
                Else
                    f("text" & i).BackColor = 10944511
                End If
            End If
        Next i
    End If
End Sub
Function ConvertNulls(v As Variant, subs As Variant) As Variant
    
    ConvertNulls = IIf(IsNull(v), subs, v)
End Function
Function IsLoaded(ByVal strFormName As String) As Boolean
    'Purpose: Determines if a given form is loaded
    'If IsLoaded("FormName") then ...
    
    Const conObjStateClosed = 0
    Const conDesignView = 0
    If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <> conObjStateClosed Then
        If Forms(strFormName).CurrentView <> conDesignView Then
            IsLoaded = True
        End If
    End If
End Function

The red text shows the highlighted problem.

I have been trying to figure this out all day.
As you can tell I am a novice!

Thanks to anyone that can help me.
 
Is this working for you in the sample database you provided?

Bob
 
Yes When I try it out as downloaded it works fine-
It;s when I import it into my database.

I have copied all files and modules, checked and checked them.
 

Attachments

What are you doing when you encounter this error?

I'm unable to reproduce it.

Bob
 
When I exit from the error, the calender opens but when I try to enter data into the input boxes for any of the dates the error comes up again not allowing any data to be entered.
The calander has boxes where data can be entered.
 
There appears to be something going on with your system.

Using the mdb you provided in Post #9, I'm able to open the calendar and enter data with no errors.

Have you checked your references?

Bob
 
Don't know what you mean by references.

What does DAO database mean?
 
You have changed the form name from frmCalender to frmCalendar however you have not changed all the occurrences of frmCalender to the "a" in the module modCalender, and potentially in other locations. This is an inherent danger of changing object and control names in established DB's.
 
You have changed the form name from frmCalender to frmCalendar however you have not changed all the occurrences of frmCalender to the "a" in the module modCalender, and potentially in other locations. This is an inherent danger of changing object and control names in established DB's.

Sorry both DB's are inconsistent in the spelling of Calendar, but I suspect this is where the issue lies.
 
THANK YOU to both of you who have helped me.

1- I had to alter a reference-RuralGuy
I found the references without help!

2- I had not changed the wrong spelling in the InputBox code-John Big Booty

:)I really do appreciate your help.
 
Does this mean you have got it working properly now?
 
Yes, I needed to tick the DAO in the references and I did have a spelling
error.

I've learned about references tonight- Thanks it is all working fine.
 

Users who are viewing this thread

Back
Top Bottom