Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I never knew it could be so much tr 1

Status
Not open for further replies.

sanders720

Programmer
Aug 2, 2001
421
0
0
US
I never knew it could be so much trouble to write an if then argument. Below are two versionns of a program. The first works, and the second (with some additions) does not.

Private Sub chkItem_Click()
Dim f As Boolean ' Flag - True/False checkbox
Dim d As Date ' Date - Date field
Dim ans As String

f = Me.MetroProcessFlag.Value
d = Me.MetroProcessDate.Value

If = Null Then
Me.MetroProcessDate.Value = Date
end if

End Sub

I have added a feature to the second listing to also check for a value in the date field (textbox). If it exists, there is no need to add it. The code just never happens!


Private Sub chkItem_Click()
Dim f As Boolean ' Flag - True/False checkbox
Dim d As Date ' Date - Date field
Dim ans As String

f = Me.MetroProcessFlag.Value
d = Me.MetroProcessDate.Value

If f = True And d <> Null Then
ans = MsgBox(&quot;The Selected Item has already been processed, would you like to run again?&quot;, vbYesNo)
If ans = vbYes Then
Me.MetroProcessDate.Value = Date
Else
Me.MetroProcessFlag = False
End If
End If

If f = True And d = Null Then
Me.MetroProcessDate.Value = Date
End If

End Sub


Thanks in advance for the help!
 
The line

If = Null Then

must be a typo?

What error on what line of code are you getting?
 
No errors, the code just does nothing and the boxes are not checked.

Sorry for the typo, The code should read...

Private Sub chkItem_Click()
Dim f As Boolean ' Flag - True/False checkbox
Dim d As Date ' Date - Date field
Dim ans As String

f = Me.MetroProcessFlag.Value
d = Me.MetroProcessDate.Value

If f = true Then
Me.MetroProcessDate.Value = Date
else
Me.MetroProcessDate.Value = Null
end if

End Sub
 
I have to admit I can't really follow what you're doing here. But here are some things to ponder:

Use IF NOT IsNull(d)
rather than d <> NULL

Also, why bother assigning things when you can just check the things directly?

If Me!ProcessFlag = TRUE and Not IsNull(Me!ProcessDate) yada yada yada....

See my point? Assignment back and forth always makes code harder to debug (as you've evidently noticed..)

Jim



Me? Ambivalent? Well, yes and no....
Another free Access forum:
More Access stuff at
 
Shouldn'y ur varuable ans be an integer? since the responses vbYes and vbNo are integers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top