Trick #1
see the watermark on the bacground when you enter your comments?
you need to post your code like this
start with the bracket "[", type the word "code" and then type the close bracket "]"
this begins a code formated procedure where your code will display properly as code.
when you finnish entering your code, type the bracket "[" then a slash "/" then the word "code" followed by a close bracket "]"
this creates the look we want and need and eliminates the possibility of spreading unwanted viruses or trojans. like this.
CODE
Private Sub Form_Load()
Private Sub txtYYYY_Exit(Cancel As Integer)
' This is where the VBA code for the date validation routine goes
Validate_Month: '2100
If Forms!frmDateChk.txtMM < "01" Then
'MsgBox "Invalid Month Entered"
GoTo Display_Bad
Else
GoTo Display_Good
End If
GoTo Exit_Rtn
If Forms!frmDateChk.txtMM > "12" Then
'MsgBox "Invalid Month Entered"
GoTo Display_Bad
Else
GoTo Display_Good
End If
GoTo Exit_Rtn
'2200_Validate_DD
'2210_Validate_Feb_DD
'2211_Validate_NonLeap_Feb_DD
If Forms!frmDateChk.txtMM = "02" Then
If CDec((Forms!frmDateChk.txtYYYY) / 4) - CInt((Forms!frmDateChk.txtYYYY) / 4) <> 0 Then
'MsgBox "non leapyear"
If (Forms!frmDateChk.txtDD < "01" Or Forms!frmDateChk.txtDD > "28") Then
'MsgBox "Invalid Feb Date entered for Non-Leap Year"
GoTo Display_Bad
Else
GoTo Display_Good
GoTo Exit_Rtn
End If
End If
End If
'2212_Validate_Leap_Feb_DD
If Forms!frmDateChk.txtMM = "02" Then
If CDec((Forms!frmDateChk.txtYYYY) / 4) - CInt((Forms!frmDateChk.txtYYYY) / 4) = 0 Then
'MsgBox "leap year"
If (Forms!frmDateChk.txtDD < "01" Or Forms!frmDateChk.txtDD > "29") Then
'MsgBox "Invalid Feb Date entered for Leap Year"
GoTo Display_Bad
Else
GoTo Display_Good
End If
GoTo Exit_Rtn
End If
End If
'2220_Validate_Apr_Jun_Sep_Nov
If (Forms!frmDateChk.txtMM = "04" Or_
Forms!frmDateChk.txtMM = "06" Or_
Forms!frmDateChk.txtMM = "09" Or_
Forms!frmDateChk.txtMM = "11") Then
'MsgBox "Apr Jun Sep or Nov"
If (Forms!frmDateChk.txtDD < "01" Or_
Forms!frmDateChk.txtDD > "30") Then
GoTo Display_Bad
Else
GoTo Display_Good
End If
GoTo Exit_Rtn
'enter logic to check DD here
End If
'2230_Validate_Other_Dd
If Forms!frmDateChk.txtMM = "01" Or_
Forms!frmDateChk.txtMM = "03" Or_
Forms!frmDateChk.txtMM = "05" Or_
Forms!frmDateChk.txtMM = "07" Or_
Forms!frmDateChk.txtMM = "08" Or_
Forms!frmDateChk.txtMM = "10" Or_
Forms!frmDateChk.txtMM = "12" Then
'MsgBox "Jan Mar May Jul Aug Oct or Dec"
If (Forms!frmDateChk.txtDD < "01" Or_
Forms!frmDateChk.txtDD > "31") Then
GoTo Display_Bad
Else
GoTo Display_Good
End If
GoTo Exit_Rtn
'enter logic to check DD
End If
'2300_Validate_YYYY
If Forms!frmDateChk.txtYYYY < "1900" Or_
Forms!frmDateChk.txtYYYY > "9999" Then
MsgBox "Invalid Year"
GoTo Display_Bad
Else
GoTo Display_Good
End If
'3000_Display_Response
Display_Good: '3100
MsgBox "Congratulations! The DATE is good!"
GoTo Exit_Rtn
Display_Bad: '3200
MsgBox "Too bad! The DATE is NO good!"
GoTo Validate_Month
Exit_Rtn:
MsgBox "all done!"
End Sub
Private Sub CmdClose_Click()
On Error GoTo Err_CmdClose_Click
DoCmd.Close
Exit_CmdClose_Click:
Exit Sub
Err_CmdClose_Click:
MsgBox Err.Description
Resume Exit_CmdClose_Click
End Sub
End Sub
ok?
All I've done here is realign your code so that it is more readable.
You should only TAB OVER on each new procedure, not on every line.
for instance
CODE
IF condition THEN
'indent all within this IF procedure to here and beyond only,
IF newcondition THEN
' indent all newcondition related code here
Print ResultsA
ELSE
' we know this belongs only to newcondition
Print ReslutsB
END IF ' all multiline IF procedures must be ENDED
'we can continue with code related to condition only
WHILE (NOT .EOF)
'this is a new procedure within condition still - a sibling of new-condition
Update condition
IF condition is TRUE THEN PRINT condition
' this is a one line IF Statement, no need to END IF or indent, except remarks
GET nextRecord
WEND
END IF
See how easy it is to read and find problems?
I have never worked with VBA but if it follows VB very closely, I think you need to seperate your SUBROUTINES
you Have all your code executing within the form load EVENT. Is this your intent?
Try looking at your code as I formatted it and see if you can fix the problem. Let me know.