473,406 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

How do you bypass the Null value in VB

anoble1
245 128KB
I have a form that has multiple fields. It has 4 fields. One of them happens to be a comment field. Sometimes there is a comment and sometimes there is not. When there is not a comment I get an error. When I debug it stops here where I have it underlined: .body = Me.Comments

How do I make it save not matter whats in the box?

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdAddToCalendar_Click()
  2.     On Error GoTo Add_Err
  3.  
  4.     'Save record first to be sure required fields are filled.
  5.     DoCmd.RunCommand acCmdSaveRecord
  6.  
  7.     Dim objOutlook As Outlook.Application
  8.     Dim objAppt As Outlook.AppointmentItem
  9.     Dim objRecurPattern As Outlook.RecurrencePattern
  10.  
  11.     Set objOutlook = CreateObject("Outlook.Application")
  12.     Set objAppt = objOutlook.CreateItem(olAppointmentItem)
  13.  
  14.     With objAppt
  15.         .Start = DateAdd("d", 90, LastEmploymentDate.Value) '& " " & Me!ApptTime
  16.         .Duration = 1440
  17.         .Subject = "Notify " & Me.NotifyName & " about " & Me.EmployeeName
  18.         .ReminderMinutesBeforeStart = 15
  19.         .ReminderSet = True
  20.         .Body = Me.Comments
  21.         .Save
  22.         .Close (olSave)
  23.     End With
  24.     'Release the AppointmentItem object variable.
  25.     Set objAppt = Nothing
  26.  
  27.     'Release the Outlook object variable.
  28.     Set objOutlook = Nothing
  29.  
  30.     MsgBox "Appointment Added!"
  31.  
  32.     Exit Sub
  33.  
  34. Add_Err:
  35.     MsgBox "Error " & Err.Number & vbCrLf & Err.Description
  36.     Exit Sub
  37. End Sub
Aug 16 '10 #1
3 1925
Delerna
1,134 Expert 1GB
Try this
additions and changes are bolded
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdAddToCalendar_Click() 
  2.     On Error GoTo Add_Err 
  3.  
  4.     'Save record first to be sure required fields are filled. 
  5.     DoCmd.RunCommand acCmdSaveRecord 
  6.     Dim strBdy as string
  7.     Dim objOutlook As Outlook.Application 
  8.     Dim objAppt As Outlook.AppointmentItem 
  9.     Dim objRecurPattern As Outlook.RecurrencePattern 
  10.  
  11.     Set objOutlook = CreateObject("Outlook.Application") 
  12.     Set objAppt = objOutlook.CreateItem(olAppointmentItem) 
  13.     strBdy=Me.Comments 
  14.     If isnull(strBdy) then strBdy ="" 
  15.     With objAppt 
  16.         .Start = DateAdd("d", 90, LastEmploymentDate.Value) '& " " & Me!ApptTime 
  17.         .Duration = 1440 
  18.         .Subject = "Notify " & Me.NotifyName & " about " & Me.EmployeeName 
  19.         .ReminderMinutesBeforeStart = 15 
  20.         .ReminderSet = True 
  21.         .Body = strBdy
  22.         .Save 
  23.         .Close (olSave) 
  24.     End With 
  25.     'Release the AppointmentItem object variable. 
  26.     Set objAppt = Nothing 
  27.  
  28.     'Release the Outlook object variable. 
  29.     Set objOutlook = Nothing 
  30.  
  31.     MsgBox "Appointment Added!" 
  32.  
  33.     Exit Sub 
  34.  
  35. Add_Err: 
  36.     MsgBox "Error " & Err.Number & vbCrLf & Err.Description 
  37.     Exit Sub 
  38. End Sub 
  39.  

EDIT
oops, did a typo
Dim strBody
....
and then used it as Bdy instead of strBdy

Thanks OldBirdman
Aug 16 '10 #2
Delerna
1,134 Expert 1GB
That's a quick and dirty fix.
There are other things you can do to ensure that null is eliminated as a problem in the first place. Like setting default values for the fields in your table
Aug 16 '10 #3
anoble1
245 128KB
That worked GREAT! Thanks!
Aug 17 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: yutlin | last post by:
Hello, Could anyone tell me if it is possible to bind a null value to a statement? I.E. $stmt->bind_param('isd',$var1,$var2,$var3); $var1 = (something indicating null); $var2 = (something...
3
by: John Morgan | last post by:
In an SQL statement which concatenates several fields I get a null value returned if any one of the fields are null. Is this to be expected? For example : SELECT tblMember.memberAddress + '...
4
by: Tom Esker | last post by:
I've got Javascript in a form that adds up all of the numbers in a column of form fields and displays a total. It works great if every field has an initial value of 0, but if any of them are null,...
3
by: Robb Gilmore | last post by:
Hello, We have a C#.NET app which is calling a Java webservice. We use the wsdl file exportted from the java webservice to create our web-reference in Visual Studio. We are able to create the...
15
by: TC | last post by:
What does it mean for an integer to have a null value? I am trying to use the DataView.Find method. That method has an integer return type which contains the "index of the row in the DataView...
1
by: David Shorthouse | last post by:
Hey folks, I am attempting to pass null as the input value from a series of textboxes if the user does not input a value prior to submit. To try and do this, I am using a vbscript function on...
2
by: shankwheat | last post by:
I'm having trouble adding two values together when one of them has a null value // These two values come from a database CEOBonusValue = 550000 CEONonEqIncentCompHidden == null This should...
7
by: monika varshney | last post by:
I have to read a database using dataset. My database has some null values. My code is working fine when there is a value in the database. But when there is a null value in the database, dataset...
0
prabirchoudhury
by: prabirchoudhury | last post by:
CRITERIA; +-------------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------------+--------------+------+-----+---------+-------+...
2
by: qwedster | last post by:
Folk! How to programattically check if null value exists in database table (using stored procedure)? I know it's possble in the Query Analyzer (see last SQL query batch statements)? But how...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.