Date with null (1 Viewer)

theinviter

Registered User.
Local time
Today, 16:35
Joined
Aug 14, 2014
Messages
237
Hi Guys;

nee help

i have created a form and when i select from drop list the item name the exp date field will be updated based on the number with each drop list but if the number is null i got error " Type Mismatch",


the code is:
Private Sub Name_AfterUpdate()

BUD = name.Column(3)
exp_date = Date + BUD

End Sub

i wanna if the number is null then Exp. date will be only current date.

please advise me how to resolve this issue
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 16:35
Joined
Aug 30, 2003
Messages
36,118
Try

BUD = Nz(name.Column(3), 0)

Name is not a good field/control name as it is a reserved word. It can conflict with the Name property of an object.
 

theinviter

Registered User.
Local time
Today, 16:35
Joined
Aug 14, 2014
Messages
237
i changed to Item_Name but still same issue
i got this line highlighted yellow:
exp_date = Date + BUD

Error " Type Mismatch"
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 16:35
Joined
Aug 30, 2003
Messages
36,118
Did you try the Nz() function I suggested?
 

theinviter

Registered User.
Local time
Today, 16:35
Joined
Aug 14, 2014
Messages
237
this is the code

Private Sub Drug_Name_AfterUpdate()
Order_Date = Now


BUD = Nz(Item_name.Column(3), 0)
exp_date = Date + BUD

End Sub
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 16:35
Joined
Aug 30, 2003
Messages
36,118
What is BUD? I assume a variable, but it isn't declared here. What exactly does that combo column contain? If it's text, you might need to convert it

BUD = CInt(Nz(Item_name.Column(3), 0))

Do you know how to set a breakpoint and step through the code, seeing what all the objects contain at runtime?
 

theinviter

Registered User.
Local time
Today, 16:35
Joined
Aug 14, 2014
Messages
237
BUD its variable contain a number , once i select form drop list item name BUD will get update with number it represent .

please this modified code :
Private Sub item_Name_AfterUpdate()
Order_Date = Now

BUD = CInt(Nz(item_name.Column(3), 0))

exp_date = Date + BUD


End Sub

run time Error "13" type mismatch
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 16:35
Joined
Aug 30, 2003
Messages
36,118
On what line? Can you attach the db here?
 

theinviter

Registered User.
Local time
Today, 16:35
Joined
Aug 14, 2014
Messages
237
the error in this line

exp_date = Date + BUD

cant attached its big size.
 

Attachments

  • Untitled.png
    Untitled.png
    16 KB · Views: 68

pbaldy

Wino Moderator
Staff member
Local time
Today, 16:35
Joined
Aug 30, 2003
Messages
36,118
From the image it appears the combo has a zero length string rather than Null. Perhaps something like

Code:
If Len(drug_name.Column(3) & vbNullString) > 0 Then
  BUD = CInt(drug_name.Column(3))
Else
  BUD = 0
End If
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 16:35
Joined
Aug 30, 2003
Messages
36,118
Happy to help! There's a one-line solution along the lines of:

BUD = IIf(Nz(drug_name.Column(3), "") = "", 0, CInt(drug_name.Column(3)))
 

Users who are viewing this thread

Top Bottom