A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Code Problem



 
 
Thread Tools Display Modes
  #1  
Old August 28th, 2005, 05:07 PM
DS
external usenet poster
 
Posts: n/a
Default Code Problem

I have this Calendar that I set-up. It works except I can't get the
Month and Year to appear in the Titlebar. It says sub or function not
defined.
Thanks
DS

Option Compare Database
Function SetCalendar(ByVal Flag As Integer) As Integer

Dim MyForm As Form, MyControl As Control
Dim MaxDays As Integer, Offset As Integer, X As Integer
Static M As Double

SetCalendar = True

Set MyForm = Forms![Calendar]

Select Case Flag
Case -2, 2
M = DateAdd("yyyy", Flag - (Flag * 0.5), M)
Case -1, 1
M = DateAdd("m", Flag, M)
Case 0
M = DateValue(DatePart("m", Date$) & "/1/" & DatePart("yyyy",
Date$))
End Select

MaxDays = Val(Mid$("312831303130313130313031", DatePart("m", M) * 2 - 1, 2))
If DatePart("m", M) = 2 Then
If DatePart("yyyy", M) Mod 4 = 0 And DatePart("yyyy", M) Mod 400
0 Then
MaxDays = 29
End If
End If

Offset = DatePart("w", M)
For X = 1 To 42
Set MyControl = MyForm("Day" & Str$(X))
If X Offset Or X Offset + MaxDays - 1 Then
MyControl = ""
Else
MyControl = X - Offset + 1
End If
Next X

X = SetTitleBar("Calendar", Format$(M, "mmm yyyy"))

End Function






  #2  
Old August 28th, 2005, 06:48 PM
Douglas J. Steele
external usenet poster
 
Posts: n/a
Default

There's no SetTitleBar function native to Access: it must be a user-defined
function that's missing from your application.

BTW, you're doing far more work than is required to determine the last day
of the month. A simple one-liner is:

MaxDays = Day(DateSerial(Year(M), Month(M) + 1, 0))


--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)



"DS" wrote in message
...
I have this Calendar that I set-up. It works except I can't get the Month
and Year to appear in the Titlebar. It says sub or function not defined.
Thanks
DS

Option Compare Database
Function SetCalendar(ByVal Flag As Integer) As Integer

Dim MyForm As Form, MyControl As Control
Dim MaxDays As Integer, Offset As Integer, X As Integer
Static M As Double

SetCalendar = True

Set MyForm = Forms![Calendar]

Select Case Flag
Case -2, 2
M = DateAdd("yyyy", Flag - (Flag * 0.5), M)
Case -1, 1
M = DateAdd("m", Flag, M)
Case 0
M = DateValue(DatePart("m", Date$) & "/1/" & DatePart("yyyy",
Date$))
End Select

MaxDays = Val(Mid$("312831303130313130313031", DatePart("m", M) * 2 - 1,
2))
If DatePart("m", M) = 2 Then
If DatePart("yyyy", M) Mod 4 = 0 And DatePart("yyyy", M) Mod 400 0
Then
MaxDays = 29
End If
End If

Offset = DatePart("w", M)
For X = 1 To 42
Set MyControl = MyForm("Day" & Str$(X))
If X Offset Or X Offset + MaxDays - 1 Then
MyControl = ""
Else
MyControl = X - Offset + 1
End If
Next X

X = SetTitleBar("Calendar", Format$(M, "mmm yyyy"))

End Function








  #3  
Old August 28th, 2005, 07:02 PM
DS
external usenet poster
 
Posts: n/a
Default

Douglas J. Steele wrote:
There's no SetTitleBar function native to Access: it must be a user-defined
function that's missing from your application.

BTW, you're doing far more work than is required to determine the last day
of the month. A simple one-liner is:

MaxDays = Day(DateSerial(Year(M), Month(M) + 1, 0))


Thanks Doug,
I went another way....
Made a form with 42 Textboxes, Named them D0, D1....to D40
Made a textbox called [FirstDate], format is: mmmm yyyy
Made a backbutton and forward button, cancel button.

Heres the code.

On the Forward Button:
Private Sub Command50_Click()
Me.FirstDate = DateAdd("m", 1, FirstDate) 'increase by 1 month
'Private Function filldates()
Dim curday As Variant, curbox As Integer
curday = DateSerial(Year(Forms!Calendar![FirstDate]),
Month(Forms!Calendar![FirstDate]), 1) 'first day of month
curday = DateAdd("d", 1 - Weekday(curday), curday) 'back to sunday
For curbox = 0 To 41 'need to loop thru 42 textboxes
Forms!Calendar("D" & curbox) = Day(curday)
Forms!Calendar("D" & curbox).Visible = False
If Month(curday) = Month(Forms!Calendar!FirstDate) Then
Forms!Calendar("D" & curbox).Visible = True
curday = curday + 1 'nextday
Next curbox
End Sub

On theBack Button:
Private Sub Command51_Click()
Me.FirstDate = DateAdd("m", -1, FirstDate) 'decrease by 1 month
Dim curday As Variant, curbox As Integer
curday = DateSerial(Year(Forms!Calendar![FirstDate]),
Month(Forms!Calendar![FirstDate]), 1) 'first day of month
curday = DateAdd("d", 1 - Weekday(curday), curday) 'back to sunday
For curbox = 0 To 41 'need to loop thru 42 textboxes
Forms!Calendar("D" & curbox) = Day(curday)
Forms!Calendar("D" & curbox).Visible = False
If Month(curday) = Month(Forms!Calendar!FirstDate) Then
Forms!Calendar("D" & curbox).Visible = True
curday = curday + 1 'nextday
Next curbox
End Sub

On Open Form:
Private Sub form_open(cancel As Integer)
Forms!Calendar![FirstDate] = Date 'set starting date to current date
Dim curday As Variant, curbox As Integer
curday = DateSerial(Year(Forms!Calendar![FirstDate]),
Month(Forms!Calendar![FirstDate]), 1) 'first day of month
curday = DateAdd("d", 1 - Weekday(curday), curday) 'back to sunday
For curbox = 0 To 41 'need to loop thru 42 textboxes
Forms!Calendar("D" & curbox) = Day(curday)
Forms!Calendar("D" & curbox).Visible = False
If Month(curday) = Month(Forms!Calendar!FirstDate) Then
Forms!Calendar("D" & curbox).Visible = True
curday = curday + 1 'nextday
Next curbox
End Sub

On the Cancel Button:
Private Sub Command52_Click()
On Error GoTo Err_Command52_Click
DoCmd.Close
Exit_Command52_Click:
Exit Sub

Err_Command52_Click:
MsgBox Err.Description
Resume Exit_Command52_Click

End Sub

This works really!
Check it out.
Thanks all!
DS


  #4  
Old August 28th, 2005, 09:29 PM
Douglas J. Steele
external usenet poster
 
Posts: n/a
Default

If it works for you, great. My advice, though, would be to use the one from
Stephen Lebans that I mentioned earlier. I've always believed it's better to
present the users with a control that they've seen before whenever possible,
and Stephen's is the standard Windows interface that they'll have seen.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)



"DS" wrote in message
...
Douglas J. Steele wrote:
There's no SetTitleBar function native to Access: it must be a
user-defined function that's missing from your application.

BTW, you're doing far more work than is required to determine the last
day of the month. A simple one-liner is:

MaxDays = Day(DateSerial(Year(M), Month(M) + 1, 0))


Thanks Doug,
I went another way....
Made a form with 42 Textboxes, Named them D0, D1....to D40
Made a textbox called [FirstDate], format is: mmmm yyyy
Made a backbutton and forward button, cancel button.

Heres the code.

On the Forward Button:
Private Sub Command50_Click()
Me.FirstDate = DateAdd("m", 1, FirstDate) 'increase by 1 month
'Private Function filldates()
Dim curday As Variant, curbox As Integer
curday = DateSerial(Year(Forms!Calendar![FirstDate]),
Month(Forms!Calendar![FirstDate]), 1) 'first day of month
curday = DateAdd("d", 1 - Weekday(curday), curday) 'back to sunday
For curbox = 0 To 41 'need to loop thru 42 textboxes
Forms!Calendar("D" & curbox) = Day(curday)
Forms!Calendar("D" & curbox).Visible = False
If Month(curday) = Month(Forms!Calendar!FirstDate) Then Forms!Calendar("D"
& curbox).Visible = True
curday = curday + 1 'nextday
Next curbox
End Sub

On theBack Button:
Private Sub Command51_Click()
Me.FirstDate = DateAdd("m", -1, FirstDate) 'decrease by 1 month
Dim curday As Variant, curbox As Integer
curday = DateSerial(Year(Forms!Calendar![FirstDate]),
Month(Forms!Calendar![FirstDate]), 1) 'first day of month
curday = DateAdd("d", 1 - Weekday(curday), curday) 'back to sunday
For curbox = 0 To 41 'need to loop thru 42 textboxes
Forms!Calendar("D" & curbox) = Day(curday)
Forms!Calendar("D" & curbox).Visible = False
If Month(curday) = Month(Forms!Calendar!FirstDate) Then Forms!Calendar("D"
& curbox).Visible = True
curday = curday + 1 'nextday
Next curbox
End Sub

On Open Form:
Private Sub form_open(cancel As Integer)
Forms!Calendar![FirstDate] = Date 'set starting date to current date
Dim curday As Variant, curbox As Integer
curday = DateSerial(Year(Forms!Calendar![FirstDate]),
Month(Forms!Calendar![FirstDate]), 1) 'first day of month
curday = DateAdd("d", 1 - Weekday(curday), curday) 'back to sunday
For curbox = 0 To 41 'need to loop thru 42 textboxes
Forms!Calendar("D" & curbox) = Day(curday)
Forms!Calendar("D" & curbox).Visible = False
If Month(curday) = Month(Forms!Calendar!FirstDate) Then Forms!Calendar("D"
& curbox).Visible = True
curday = curday + 1 'nextday
Next curbox
End Sub

On the Cancel Button:
Private Sub Command52_Click()
On Error GoTo Err_Command52_Click
DoCmd.Close
Exit_Command52_Click:
Exit Sub

Err_Command52_Click:
MsgBox Err.Description
Resume Exit_Command52_Click

End Sub

This works really!
Check it out.
Thanks all!
DS




  #5  
Old August 29th, 2005, 12:21 AM
DS
external usenet poster
 
Posts: n/a
Default

Douglas J. Steele wrote:
If it works for you, great. My advice, though, would be to use the one from
Stephen Lebans that I mentioned earlier. I've always believed it's better to
present the users with a control that they've seen before whenever possible,
and Stephen's is the standard Windows interface that it with a sey'll have seen.

Thanks, Douglas
Sincerely,
DS
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
error 550 won't deliver theMooooo General Discussion 3 March 29th, 2005 12:47 PM
0x80040109 error when sending from SSL SMTP krouse General Discussion 7 March 15th, 2005 01:55 AM
VBA Code problem error 9 Speedy General Discussion 19 October 15th, 2004 09:05 PM
Problem is clicking min. button, not minimizing in code paul Using Forms 1 August 13th, 2004 02:22 PM
Problem with recent Drop Down List Code krislyn General Discussion 1 August 2nd, 2004 11:10 PM


All times are GMT +1. The time now is 04:13 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.