Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6205905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:21:20+00:00 2026-05-24T05:21:20+00:00

Working on a script in Microsoft VBA to take a massive flat database and

  • 0

Working on a script in Microsoft VBA to take a massive flat database and split it between about 20 different tables. The script consists mainly of opening a table, checking every row in the flat database to make sure it’s not a duplicate, then adding the necessary fields. Repeat for every table.

The first time I ran it everything was going well until I tried to process the name O'Malley. I think it’s obvious what went wrong. A quick search on Google turned up this related StackOverflow post. I took their advice and added Replace(str, "'", "''") to every field before inputting it into the new tables. Now I’ve run into a new problem and Google is less helpful.

Replace(null, "'", "''") causes a run-time error, and the flat database is just riddled with null values. I can add an extra line above every Replace() call to check IsNull() and if so put null into the database instead of Replace(str, "'", "''"), although I would prefer a solution that can fit into a single line if possible. Is there any more elegant way to solve this dilemma, or will I need 216 If statements in my code?

EDIT –

Another reason that I’m searching for a more elegant solution is my duplicate checking code. At the moment I have something like the following:

        'Check for duplicates
        'Assume student is duplicate if it shares:
        '   (StudentName and School) or SSN
        Set rstDuplicate = CurrentDb.OpenRecordset("select * from Student where (StudentName = '" & Replace(rstFrom("Student").Value, "'", "''") & "' AND School = '" & Replace(rstFrom("School").Value, "'", "''") & "') OR SSN = '" & Replace(rstFrom("Social").Value, "'", "''") & "'")
        If rstDuplicate.RecordCount = 0 Then
            'Duplicate was not found
            rstTo.AddNew
            ' Add fields to the new table
            rstTo.Update
        End If

Since the Replace() calls are inline with the duplicate checking, if I were to instead use If statements to check for null then I would have to either save the result to a string or update to flat database. A function that returns Replace(str, "'", "''") OR null without the need for extra variables would be ideal.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T05:21:22+00:00Added an answer on May 24, 2026 at 5:21 am

    If you want to keep everything inline, you can use an immediate If function (IIf):

    IIf(IsNull(rstFrom("Student").Value), " Is Null", "= " & Replace(rstFrom("Student").Value)
    

    That will be a nightmare to read and maintain, though. You are better off writing your own function to handle the change in comparison operator as well as the apostrophe escaping:

    Function CompFld(Val As Variant) As String
        If IsNull(Val) Then
            CompFld = " Is Null "
        Else
            CompFld = "= '" & Replace(Val, "'", "''") & "' "
        End If
    End Function
    

    Use it as so:

    Dim SQL As String
    SQL = "SELECT * FROM Student " & _
          "WHERE (StudentName " & CompFld(rstFrom("Student").Value) & " AND " & _
          "       School " & CompFld(rstFrom("School").Value) & ") " & _
          "   OR (SSN " & CompFld(rstFrom("Social").Value) & ") "
    Set rstDuplicate = CurrentDb.OpenRecordset(SQL)
    If rstDuplicate.RecordCount = 0 Then
        'Duplicate was not found
        rstTo.AddNew
        ' Add fields to the new table
        rstTo.Update
    End If
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've just about got the jPicker script working flawlessly in my app. However, the
Hello I am working on a SQL database Using Microsoft SQL server 2008 R2
I have a script working well for creating ad hoc iPhone builds. I can
So I have my upload script working just fine, but now it's a matter
I'm trying to get this simple PowerShell script working, but I think something is
I'm having little trouble creating a script working with URLs. I'm using urllib.urlopen() to
In tcsh , I have the following script working: #!/bin/tcsh setenv X_ROOT /some/specified/path setenv
Working on a script to collect users browser history with time stamps ( educational
I'm working on a script in PHP that needs to get some info from
I am working on a script to send data to a mysql table and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.