Solved

VBA replace function gives "Invalid use of null" error

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

816 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

13 Experts available now in Live!

Get 1:1 Help Now