If Null stop code!

B

Bob Quintal

I have this code on a control, but if DailyChargeRate1 is Null
I am getting an Access Error
Can I add to code , If tbDailyChargeRate1 is Null , Loop! ,
Stop! , Ignor! the rest of the code
Thanks If you can Help......Bob

Private Sub cmdFRate1_Click()
Me!tbDailyChargeRate1 = Me!tbDailyChargeRate1 + 1
End Sub
Just branch around the code if it's null

Private Sub cmdFRate1_Click()
if Not isnull(me!tbDailyChargeRate1 then
Me!tbDailyChargeRate1 = Me!tbDailyChargeRate1 + 1
End Sub
 
B

Bob V

I have this code on a control, but if DailyChargeRate1 is Null I am getting
an Access Error
Can I add to code , If tbDailyChargeRate1 is Null , Loop! , Stop! , Ignor!
the rest of the code
Thanks If you can Help......Bob

Private Sub cmdFRate1_Click()
Me!tbDailyChargeRate1 = Me!tbDailyChargeRate1 + 1
End Sub
 
R

Rob Parker

Hi Bob,

Try this:

Private Sub cmdFRate1_Click()
If Not IsNull(Me!tbDailyChargeRate1) Then
Me!tbDailyChargeRate1 = Me!tbDailyChargeRate1 + 1
End If
End Sub

HTH,

Rob
 
J

JK

Hi Bob,

Me!tbDailyChargeRate1 = Nz(Me!tbDailyChargeRate1,0) + 1

Alternatively:

Me!tbDailyChargeRate1 = IIF(IsNull(Me!tbDailyChargeRate1), _
Null, Me!tbDailyChargeRate1 + 1)


Regards/Jacob

|
| I have this code on a control, but if DailyChargeRate1 is Null I am
getting
| an Access Error
| Can I add to code , If tbDailyChargeRate1 is Null , Loop! , Stop! , Ignor!
| the rest of the code
| Thanks If you can Help......Bob
|
| Private Sub cmdFRate1_Click()
| Me!tbDailyChargeRate1 = Me!tbDailyChargeRate1 + 1
| End Sub
|
|
 
B

Bob V

Would you Believe it all 3 codes from JK and Rob still gave me the same
error
Run Time Error 13
Type Mismatch
Thanks for your help...Bob
 
B

Bob V

Forget about that Guys, found out that if I changed the data I could not
always hold the same data
But this Date Control does the same thing if there is no date in
tbStartDate1
Thanks if you can help...Bob

Private Sub cmdFSDate1_Click()
Me.tbStartDate1 = DateAdd("d", 1, Me.tbStartDate1)
tbEndDate1.SetFocus
tbEndDate1_LostFocus
End Sub
 
P

pietlinden

I have this code on a control, but if DailyChargeRate1 is Null I am getting
an Access Error
Can I add to code , If tbDailyChargeRate1 is Null , Loop! , Stop! , Ignor!
the rest of the code
Thanks If you can Help......Bob

Private Sub cmdFRate1_Click()
Me!tbDailyChargeRate1 = Me!tbDailyChargeRate1 + 1
End Sub

well, convert the null to zero, then add...

Me!tbDailyChargeRate1=Nz(Me!tbDailyChargeRate1) + 1
 
J

John W. Vinson

Forget about that Guys, found out that if I changed the data I could not
always hold the same data
But this Date Control does the same thing if there is no date in
tbStartDate1
Thanks if you can help...Bob

Private Sub cmdFSDate1_Click()
Me.tbStartDate1 = DateAdd("d", 1, Me.tbStartDate1)
tbEndDate1.SetFocus
tbEndDate1_LostFocus
End Sub

What do you want to happen if tbStartDate1 is NULL? If you want to just leave
it null use

Private Sub cmbFSDate1_Click()
If Not IsNull(Me.tbStartDate1) Then
Me.tbStartDate1 = DateAdd("d", 1, Me.tbStartDate1)
End If
Me.EndDate1.SetFocus
End Sub

The "LostFocus" line does nothing and should be omitted.

John W. Vinson [MVP]
 
B

Bob V

Thanks Bob , how would i correct this, If there is no date and I click this
control I am getting the same error.......Thanx Bob
Private Sub cmdFSDate1_Click()
Me.tbStartDate1 = DateAdd("d", 1, Me.tbStartDate1)
tbEndDate1.SetFocus
tbEndDate1_LostFocus
End Sub
 
B

Bob Quintal

Thanks Bob , how would i correct this, If there is no date and
I click this control I am getting the same error.......Thanx

The same way...

Private Sub cmdFSDate1_Click()
If NOT IsNull(me.tbStartDate1) then
Me.tbStartDate1 = DateAdd("d", 1, Me.tbStartDate1)
tbEndDate1.SetFocus
tbEndDate1_LostFocus end if
End Sub
Bob Quintal said:
Just branch around the code if it's null

Private Sub cmdFRate1_Click()
if Not isnull(me!tbDailyChargeRate1 then
Me!tbDailyChargeRate1 = Me!tbDailyChargeRate1 + 1
End Sub
 
Top