Solved

VBA replace function gives "Invalid use of null" error

Posted on 2013-11-11
5
893 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 119

Assisted Solution

by:Rey Obrero
Rey Obrero 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now