Error Checking for Entry in a Text Box

  • Thread starter Thread starter Steve
  • Start date Start date
S

Steve

Working on a form that if you enter in a title in a text box, it
appears on the chart itself as a title, however, if you do not enter a
title, it gives me a runtime error. Trying to figure out a way to error
check and either A) make it so they have to enter a title in the text
box for the chart or B) so if you do not enter a title in the text box,
the rest of the information will still print in the title. This is some
code i've been fiddling around with the last couple of days.



Private Sub Form_Load()

If Form_monthlyCharts.Title.Value = IsNull Then
Call No_Title
Else
Call Title
End If

End Sub

Private Sub No_Title()

Me.AvgLevelChart.Object.ChartTitle.Text =
Forms!monthlyCharts!lakeCombo.Value + " - " + "Average Level Data"
Me.AvgRainChart.Object.ChartTitle.Text =
Forms!monthlyCharts!lakeCombo.Value + " - " + "Average Rain Data"
Me.LakeDataChart.Object.ChartTitle.Text =
Forms!monthlyCharts!lakeCombo.Value + " - " + "Lake Data"
Me.LevelDataChart.Object.ChartTitle.Text =
Forms!monthlyCharts!lakeCombo.Value + " - " + "Level Data"

End Sub

Private Sub Title()

Me.AvgLevelChart.Object.ChartTitle.Text =
Forms!monthlyCharts!lakeCombo.Value + " - " + "Average Level Data" + "
- " + Forms!monthlyCharts!Title
Me.AvgRainChart.Object.ChartTitle.Text =
Forms!monthlyCharts!lakeCombo.Value + " - " + "Average Rain Data" + " -
" + Forms!monthlyCharts!Title
Me.LakeDataChart.Object.ChartTitle.Text =
Forms!monthlyCharts!lakeCombo.Value + " - " + "Lake Data" + " - " +
Forms!monthlyCharts!Title
Me.LevelDataChart.Object.ChartTitle.Text =
Forms!monthlyCharts!lakeCombo.Value + " - " + "Level Data" + " - " +
Forms!monthlyCharts!Title

End Sub
 
Steve, you can't compare anything to Null.
Instead, use the IsNull() function:
If IsNull(Form_monthlyCharts.Title.Value) Then
Call No_Title
Else
Call Title
End If

Also, use the ampersand for concatenation in preference to the plus (unless
you have a special reason.) Access can attempt addition if you use the plus:
Me.AvgLevelChart.Object.ChartTitle.Text = _
Forms!monthlyCharts!lakeCombo.Value & " - Average Level Data"
 
thank you so much. i had been fiddling with this a couple of ways since
friday, and its good to know i wasn't far off; just needed that extra
little push. thanks allen!

-steve-
 
Back
Top