Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VBA replace function gives "Invalid use of null" error

Posted on 2013-11-11
5
Medium Priority
?
1,015 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 800 total points
ID: 39639824
try

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

Accepted Solution

by:
mbizup earned 1200 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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
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 …

618 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