Solved

VBA replace function gives "Invalid use of null" error

Posted on 2013-11-11
5
949 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

734 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