Solved

VBA replace function gives "Invalid use of null" error

Posted on 2013-11-11
5
934 Views
Last Modified: 2013-11-11
The following text field is loaded into a variable.
When I use the replace function to fix the apostrophe in the string I get the null error above
The apostrophe needs to be set to '' so I can use it to insert into another table.

This replace method has worked on other text field types.

Text data in variable p_sibio

Mark has 30 years' experience in quality management and organizational improvement. He is VP of Quality Systems Division at Orchard Material Technology. OMT focuses on innovations in energy, the environment and material sciences. Prior to OMT, He was President at Harold Communications . President at the National Council of Performance Excellence and COO at TUO America. He's a board member of the Society of Organizational Learning, the VT Council for Quality and MassExcellence. He was a National Malcolm Baldrige Examiner and is a Senior Member of ASQ. Mark has a BS in Industrial Engineering and a Masters in Management Science.

p_s1bio = Replace(p_s1bio, "'", "''")

Error: invalid use of null pointing to the replace statement

Any suggestions to resolve this error or is there something else in the data string I am not seeing?
0
Comment
Question by:TOWELLR
  • 2
  • 2
5 Comments
 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 200 total points
ID: 39639824
try

p_s1bio = Replace(p_s1bio & Chr(39), Chr(39), "''")
0
 
LVL 61

Accepted Solution

by:
mbizup earned 300 total points
ID: 39639861
Or this if you simply want to leave nulls blank:

 p_s1bio = Replace(NZ(p_s1bio, "") , "'", "''")

Open in new window

0
 

Author Comment

by:TOWELLR
ID: 39639877
capricorn1

Your suggestion cleared the null error but left a trailing quote

mbizup

Your suggestion works fine.
I guess I had some null value in the string that I could not observe.

Thanks to both for the insight.
0
 
LVL 61

Expert Comment

by:mbizup
ID: 39639915
<< I guess I had some null value in the string that I could not observe. >>

You wouldn't have portions of a field or string being null.  It can only be Null or not null (not anything in between).  Just hazarding a guess that this function was operating on different records in some table, and that in some records, that field is completely blank (ie: Null - absence of value).

Are you a Hokie?  Either way, glad to help with something seemingly related to my alma mater :-)
0
 

Author Comment

by:TOWELLR
ID: 39639946
You know what you are correct.  I got so fixated to resolve the quote issue and thought the null error was on the same record.  I was thinking the replace function was just misbehaving in some way.  It was actually from the next record in the table that had no p_sibio value.

I better institute some better error handling.

Thanks
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question