madetoheal13
MIS
Hey guys. I am inserting a pop up calendar into a field of a form. I thought it was coded right...but when I tab over to the field on the actual form I get an error message.
The code:
Option Compare Database
Option Explicit
Private strGlobalUser As String
'This declares the MonthCalendar Class
Private mc As clsMonthCal
Private Sub Date_Trained_Enter()
Dim blRet As Boolean
Dim dtStart As Date, dtEnd As Date
dtStart = Nz(Me.Date_Trained, 0)
dtEnd = 0
blRet = ShowMonthCalendar(mc, dtStart, dtEnd)
If blRet = True Then
Me.Date_Trained = dtStart
Else
'Guess what you forgot to do?
'You forgot to select a date!
End If
End Sub
Private Sub Form_Load()
'Create an instance of our Class
Set mc = New clsMonthCal
'Set the hWndForm Property
mc.hWndForm = Me.hWnd
End
'Load proper source for the specific user
'Check if the User is OK, and if it's OK, create the record source
Dim DB As Database
Set DB = CodeDb
Dim rstUser As Recordset
Dim strCurrentUser As String
Set rstUser = DB.OpenRecordset("CurrentUser", dbOpenDynaset)
If rstUser.RecordCount <> 1 Then
'One record is OK
strCurrentUser = rstUser.Fields(0)
rstUser.Close
Select Case strCurrentUser
Case "GG"
Case "JB"
Case "JJ"
Case "JS"
Case "KK"
Case "TH"
Case Else
strCurrentUser = ""
End Select
If Trim(strCurrentUser) <> "" Then
Me.RecordSource = _
"SELECT " & Trim(strCurrentUser) & "Face2Face.CustomerID, " & Trim(strCurrentUser) & "Face2Face.[Current Prospect?], " & _
Trim(strCurrentUser) & "Face2Face.[Current Account?], " & Trim(strCurrentUser) & "Face2Face.[Boxed LW14], " & _
Trim(strCurrentUser) & "Face2Face.[Display LW14], " & Trim(strCurrentUser) & "Face2Face.[Boxed LW24], " & _
Trim(strCurrentUser) & "Face2Face.[Display LW24], " & Trim(strCurrentUser) & "Face2Face.[Boxed LW44], " & _
Trim(strCurrentUser) & "Face2Face.[Display LW44], " & Trim(strCurrentUser) & "Face2Face.[Boxed WTA], " & _
Trim(strCurrentUser) & "Face2Face.[Display WTA], " & Trim(strCurrentUser) & "Face2Face.[Boxed Cleaner], " & _
Trim(strCurrentUser) & "Face2Face.[Dipslay Cleaner], " & Trim(strCurrentUser) & "Face2Face.[Boxed Fragrance], " & _
Trim(strCurrentUser) & "Face2Face.[Display Fragrance], " & Trim(strCurrentUser) & "Face2Face.[Location and Placement of Display], " & _
Trim(strCurrentUser) & "Face2Face.[# of Associates Trained], " & Trim(strCurrentUser) & "Face2Face.[AOS Models & Quantity], " & _
Trim(strCurrentUser) & "Face2Face.Display, " & Trim(strCurrentUser) & "Face2Face.[Customer Training], " & _
Trim(strCurrentUser) & "Face2Face.[WTA & Cleaner], " & Trim(strCurrentUser) & "Face2Face.[Review RMA Policy], " & _
Trim(strCurrentUser) & "Face2Face.[Video Running], " & _
Trim(strCurrentUser) & "Face2Face.[Posters Up], " & _
Trim(strCurrentUser) & "Face2Face.Advertising, " & _
Trim(strCurrentUser) & "Face2Face.Other2, " & _
Trim(strCurrentUser) & "Face2Face.[Competitor Information], " & _
Trim(strCurrentUser) & "Face2Face.[Other Brands Sold], " & _
Trim(strCurrentUser) & "Face2Face.[Weber, Dyson, or Meile], " & _
Trim(strCurrentUser) & "Face2Face.[Week #], " & _
Trim(strCurrentUser) & "Face2Face.[Date Trained], " & _
Trim(strCurrentUser) & "Face2Face.[Time Trained] " & _
"FROM " & Trim(strCurrentUser) & "Face2Face;"
Else
'If it is the user without poermission
MsgBox ("You cannot run this macro. Please, contact application administrator")
Set rstUser = DB.OpenRecordset("CurrentUser", dbOpenDynaset)
Do While Not rstUser.EOF
rstUser.Delete
rstUser.MoveNext
Loop
rstUser.Close
DoCmd.Close acForm, "F2F", acSaveNo
DoCmd.OpenForm ("VentaInformationSystemLogin")
End If
Else
'It is possible that more then one user starts the application.
'In this case we do not know which user needs the own table
MsgBox ("Too many users. Please login again")
Do While Not rstUser.EOF
rstUser.Delete
rstUser.MoveNext
Loop
rstUser.Close
DoCmd.Close acForm, "F2F", acSaveNo
DoCmd.OpenForm ("VentaInformationSystemLogin")
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
'This is required in case user Closes Form with the
'Calendar still open. It also handles when the
'user closes the application with the Calendar still open.
If Not mc Is Nothing Then
If mc.IsCalendar Then
Cancel = 1
Exit Sub
End If
Set mc = Nothing
End If
End Sub
-----------------------------------------------------------
The error:
"Invalid MonthCalendar object!"
The MonthCalendar class instance you passed to this function is INVALID! YOu must instantiate the MonthCalendar Class object before you call this function. The code behind the sample Form shows you how to do this in the Form's Load event.
'This must appear here!
'Create an instance of our Class
Private Sub Form_Load()
Set mc=New clsMonthCal
'You must set the class hWndForm prop!!!
mc.hWndForm=Me.hWnd
-----------------------------------------------------------
Please help me out with this!!!
madetoheal13
The code:
Option Compare Database
Option Explicit
Private strGlobalUser As String
'This declares the MonthCalendar Class
Private mc As clsMonthCal
Private Sub Date_Trained_Enter()
Dim blRet As Boolean
Dim dtStart As Date, dtEnd As Date
dtStart = Nz(Me.Date_Trained, 0)
dtEnd = 0
blRet = ShowMonthCalendar(mc, dtStart, dtEnd)
If blRet = True Then
Me.Date_Trained = dtStart
Else
'Guess what you forgot to do?
'You forgot to select a date!
End If
End Sub
Private Sub Form_Load()
'Create an instance of our Class
Set mc = New clsMonthCal
'Set the hWndForm Property
mc.hWndForm = Me.hWnd
End
'Load proper source for the specific user
'Check if the User is OK, and if it's OK, create the record source
Dim DB As Database
Set DB = CodeDb
Dim rstUser As Recordset
Dim strCurrentUser As String
Set rstUser = DB.OpenRecordset("CurrentUser", dbOpenDynaset)
If rstUser.RecordCount <> 1 Then
'One record is OK
strCurrentUser = rstUser.Fields(0)
rstUser.Close
Select Case strCurrentUser
Case "GG"
Case "JB"
Case "JJ"
Case "JS"
Case "KK"
Case "TH"
Case Else
strCurrentUser = ""
End Select
If Trim(strCurrentUser) <> "" Then
Me.RecordSource = _
"SELECT " & Trim(strCurrentUser) & "Face2Face.CustomerID, " & Trim(strCurrentUser) & "Face2Face.[Current Prospect?], " & _
Trim(strCurrentUser) & "Face2Face.[Current Account?], " & Trim(strCurrentUser) & "Face2Face.[Boxed LW14], " & _
Trim(strCurrentUser) & "Face2Face.[Display LW14], " & Trim(strCurrentUser) & "Face2Face.[Boxed LW24], " & _
Trim(strCurrentUser) & "Face2Face.[Display LW24], " & Trim(strCurrentUser) & "Face2Face.[Boxed LW44], " & _
Trim(strCurrentUser) & "Face2Face.[Display LW44], " & Trim(strCurrentUser) & "Face2Face.[Boxed WTA], " & _
Trim(strCurrentUser) & "Face2Face.[Display WTA], " & Trim(strCurrentUser) & "Face2Face.[Boxed Cleaner], " & _
Trim(strCurrentUser) & "Face2Face.[Dipslay Cleaner], " & Trim(strCurrentUser) & "Face2Face.[Boxed Fragrance], " & _
Trim(strCurrentUser) & "Face2Face.[Display Fragrance], " & Trim(strCurrentUser) & "Face2Face.[Location and Placement of Display], " & _
Trim(strCurrentUser) & "Face2Face.[# of Associates Trained], " & Trim(strCurrentUser) & "Face2Face.[AOS Models & Quantity], " & _
Trim(strCurrentUser) & "Face2Face.Display, " & Trim(strCurrentUser) & "Face2Face.[Customer Training], " & _
Trim(strCurrentUser) & "Face2Face.[WTA & Cleaner], " & Trim(strCurrentUser) & "Face2Face.[Review RMA Policy], " & _
Trim(strCurrentUser) & "Face2Face.[Video Running], " & _
Trim(strCurrentUser) & "Face2Face.[Posters Up], " & _
Trim(strCurrentUser) & "Face2Face.Advertising, " & _
Trim(strCurrentUser) & "Face2Face.Other2, " & _
Trim(strCurrentUser) & "Face2Face.[Competitor Information], " & _
Trim(strCurrentUser) & "Face2Face.[Other Brands Sold], " & _
Trim(strCurrentUser) & "Face2Face.[Weber, Dyson, or Meile], " & _
Trim(strCurrentUser) & "Face2Face.[Week #], " & _
Trim(strCurrentUser) & "Face2Face.[Date Trained], " & _
Trim(strCurrentUser) & "Face2Face.[Time Trained] " & _
"FROM " & Trim(strCurrentUser) & "Face2Face;"
Else
'If it is the user without poermission
MsgBox ("You cannot run this macro. Please, contact application administrator")
Set rstUser = DB.OpenRecordset("CurrentUser", dbOpenDynaset)
Do While Not rstUser.EOF
rstUser.Delete
rstUser.MoveNext
Loop
rstUser.Close
DoCmd.Close acForm, "F2F", acSaveNo
DoCmd.OpenForm ("VentaInformationSystemLogin")
End If
Else
'It is possible that more then one user starts the application.
'In this case we do not know which user needs the own table
MsgBox ("Too many users. Please login again")
Do While Not rstUser.EOF
rstUser.Delete
rstUser.MoveNext
Loop
rstUser.Close
DoCmd.Close acForm, "F2F", acSaveNo
DoCmd.OpenForm ("VentaInformationSystemLogin")
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
'This is required in case user Closes Form with the
'Calendar still open. It also handles when the
'user closes the application with the Calendar still open.
If Not mc Is Nothing Then
If mc.IsCalendar Then
Cancel = 1
Exit Sub
End If
Set mc = Nothing
End If
End Sub
-----------------------------------------------------------
The error:
"Invalid MonthCalendar object!"
The MonthCalendar class instance you passed to this function is INVALID! YOu must instantiate the MonthCalendar Class object before you call this function. The code behind the sample Form shows you how to do this in the Form's Load event.
'This must appear here!
'Create an instance of our Class
Private Sub Form_Load()
Set mc=New clsMonthCal
'You must set the class hWndForm prop!!!
mc.hWndForm=Me.hWnd
-----------------------------------------------------------
Please help me out with this!!!
madetoheal13