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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Handle a Null

Status
Not open for further replies.

Ebes1099

Technical User
Jul 8, 2009
156
US
I'm trying to write an if statement using the month function. I want certain boxes to be disabled if the month is before August and Enabled otherwise. I'm using the month() function to get the value of the month. Problem is, whenever that field goes blank, I get a null value error. How can I handle this?

Here's the code...

Private Sub Form_Current()
If (month(Me.valRenewalMonth) < 8) Then
Me.valMbrs2009.Enabled = False
Me.valRevAcct2009.Enabled = False
Me.valCustRevInc2009.Enabled = False
Me.valDefRevInc2009.Enabled = False
Me.valBenAdjFactor2009.Enabled = False
Else
Me.valMbrs2009.Enabled = True
Me.valRevAcct2009.Enabled = True
Me.valCustRevInc2009.Enabled = True
Me.valDefRevInc2009.Enabled = True
Me.valBenAdjFactor2009.Enabled = True
End If

End Sub
 
If Month(Nz(Me.valRenewalMonth), 2) < 8 Then

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
How are ya Ebes1099 . . .
[ol][li]In the [blue]Tag[/blue] property of the textboxes in question, put a question mark [blue]?[/blue] ([red]no quotations please![/red]).[/li]
[li]Copy/paste the following to the event your using:
Code:
[blue]   For Each ctl In Me.Controls
      If Trim(ctl & "") <> "" Then
         If ctl.Tag = "[purple][b]?[/b][/purple]" Then
            ctl.Enabled = (Month(Me.valRenewalMonth) >= 8)
         End If
      End If
   Next[/blue]
[/li]
[li]Perform your testing ...[/li][/ol]
Note: if your using a [blue]continuous form[/blue] this schema won't work and you'll have to resort to [blue]conditional formatting[/blue]. Let us know.

[blue]Your Thoughts? . . .[/blue]

BTW: Welcome to [blue]Tek-Tips![/blue] [thumbsup2] Do have a look at one of the links at the bottom of my post. The links will help you [blue]ask better questions[/blue], get [blue]quick responses[/blue], [blue]better answers[/blue], and insite into [blue]etiquette[/blue] here in the forums. Again . . . Welcome to [blue]Tek-Tips![/blue] [thumbsup2] [blue]Its Worthy Reading![/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Thanks for the help. I ended up using the Nz() function. I had tried that earlier but was using it outside the Month() function. I'm assuming with that code, it sets the value equal to 2 if the month is null? That should be ok.

Anyway, thanks for the help on this!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top