"Compile error: Variable not defined"

cedtech23

Registered User.
Local time
Today, 13:40
Joined
Jan 28, 2006
Messages
25
I have a standard Module called DisplayTime

that contains

Code:
Option Compare Database
Option Explicit
Public txtBox As TextBox

Public Function GetTime(txtBox As TextBox)

DoCmd.OpenForm frmGetTime

End Function

Basically this function opens a form frmGetTime

within the frmGetTime


Code:
Option Compare Database
Option Explicit
Dim intRawHour As Integer
Dim strRawMinutes As String 'Reason this is String and not Integer 

because of 00 value
Dim strAMPM As String
Dim CompleteTime As Variant

Private Sub cmdOK_Click()

intRawHour = Forms!frmGetTime!cboHour
strRawMinutes = Forms!frmGetTime!cboMinutes
strAMPM = Forms!frmGetTime!cboAMPM

CompleteTime = TimeValue(intRawHour & ":" & strRawMinutes & strAMPM)

txtBox.Value = CompleteTime

Debug.Print CompleteTime

End Sub

I placed =GetTime([txtCheckIn]) on the On Click property of text

box "txtCheckIn" within form frmGetTime

When I click within "txtCheckIn" I get the following error
"Compile error: Variable not defined"

I can't figure out what variable the error is refering to..
Also will my function work?

It's suppose to pass the value of time to the text box

I attached the DB
 

Attachments

I figured OpenForm was looking for a string value:

But know I get the following error

"Run-time error '91':
Object variable or With block variable not set"

When I hit the debug it goes to this line

txtBox.Value = CompleteTime
 
I changed up the code to

Code:
Public CompleteTime As Date



Public Function GetTime(txtbox As Control) As Date

DoCmd.OpenForm "frmGetTime", , , , , acDialog

txtbox = CompleteTime

End Function


Code:
Private Sub cmdOK_Click()

CompleteTime = Forms!frmGetTime!cboHour & ":" & Forms!frmGetTime!cboMinutes & Forms!frmGetTime!cboAMPM

DoCmd.Close acForm, "frmGetTime"

Debug.Print CompleteTime

End Sub

This worked great but know I have a formatting issue, I am trying to figure out.

Instead of getting results like 7:15:00 PM
How do I just get 7:15 PM?
 

Users who are viewing this thread

Back
Top Bottom