Deleting the first character of a string when importing (1 Viewer)

troncarver

Registered User.
Local time
Today, 00:49
Joined
Jan 31, 2006
Messages
14
Hello ALL,

I need some VB code that will delete the first character of an 11 digit number string when I am importing this field into an access table??? THanks alot my peoples...
 

Matt Greatorex

Registered User.
Local time
Today, 03:49
Joined
Jun 22, 2005
Messages
1,019
Dim li_String as Integer

li_String = value

li_String = Right(li_String, 10)
 

ghudson

Registered User.
Local time
Today, 03:49
Joined
Jun 8, 2002
Messages
6,194
After you import the data "as-is", you could use an update query to update the values by stripping of the first value of the 11 character string.

Post your db and I will make the query for you.
 

troncarver

Registered User.
Local time
Today, 00:49
Joined
Jan 31, 2006
Messages
14
thank you

the input mask is for writing data to a table i am assuming? For my db, the user is entering the number on a .asp form and the vb script is simply finding that value in the ndc field and returning it to a display on the asp page.

So with this update query i can essentially import this field as is (12345-67-8901) and update it to populate the field values with (2345678901). that way when the user types in 2345678901 the query will find actaully find that entry.

Right now I have a batch file that that calls the macro mcrRun to open the db up, delete the old data, import the new text file and close the db. So im assuming we would have to execute that query right after the transfertext in that macro?

I really really appreciate you taking the time to help me out. That is good karma my friend

Terron
 

Attachments

  • rxinv.zip
    128.4 KB · Views: 114

ghudson

Registered User.
Local time
Today, 03:49
Joined
Jun 8, 2002
Messages
6,194
I have attached my fix. The qDisplayExample query will show you what the stripped value will look like using the Right() function Right([ndc],12) You have an 11 digit number but the hyphens add two more for a total of 13 characters.

The qStrip1stCharacter query will actually replace the ndc values in the drug table with the new values [minus] the first character in the original string. You should run it right after the data is imported.

I also added my custom VerifyImportErrorTables() function. You should run it after your import function for it will search and delete any import error tables for which you have a bunch.

Good luck!
 

Attachments

  • rxinv-1.zip
    74.6 KB · Views: 112

troncarver

Registered User.
Local time
Today, 00:49
Joined
Jan 31, 2006
Messages
14
Thank you so much

ghudson,

That is awesome, thank you so much. If i could just have your quick help i one more thing that would be superb. Now what would the syntax be for an update query, that after this query runs would then delete the 5th and 10th characters which would be the hyphens?????

Hey thanks alot ghudson you saved me alot of valuable time!!
 

checoturco

Registered User.
Local time
Today, 00:49
Joined
Oct 17, 2005
Messages
76
That is awesome, thank you so much. If i could just have your quick help i one more thing that would be superb. Now what would the syntax be for an update query, that after this query runs would then delete the 5th and 10th characters which would be the hyphens?????


hi troncarver
i buid a form with a button with this code and it works

Private Sub Command0_Click()
Dim rs As Recordset
Dim db As Database
Dim strnewstring As String
Dim strfind As String
Dim strreplace As String
Dim teste As String

Set db = CurrentDb

strfind = "-"
strreplace = ""

DoCmd.SetWarnings False
Set rs = New ADODB.Recordset
rs.Open "select ndc from drug;", CurrentProject.Connection, adOpenKeyset, adLockOptimistic
If Not rs.EOF Then
Do Until rs.EOF
strnewstring = Replace(rs("ndc"), strfind, strreplace)
' Debug.Print strnewstring
DoCmd.RunSQL " update drug set ndc='" & strnewstring & "' where ndc like '" & rs("ndc") & "';"
rs.MoveNext
Loop
End If

rs.Close
Set rs = Nothing

be carefull because you have a blank field on ndc column,line 984
ndc Name QOH Actual
BRUSH TEETH 815 ,

if you could have this, put a where clause in the openrecordset query

checoturco
 
Last edited:

ghudson

Registered User.
Local time
Today, 03:49
Joined
Jun 8, 2002
Messages
6,194
Since I think that you will be more comfortable with SQL I have created a new query "qRemoveHyphens" that uses the Replace() function to remove the hyphens. The criteria Like *-* will ensure only the records with a hyphen will be affected. Enjoy!

Searching the forum will help you find a lot of good stuff on how to help you with your Access programming questions.
 

Attachments

  • rxinv-2.zip
    74.1 KB · Views: 112

troncarver

Registered User.
Local time
Today, 00:49
Joined
Jan 31, 2006
Messages
14
Replace function undefined

hey ghudson, when i run that query it is displaying that the Replace() function is undefined? I am running access 2000, has that function net bet defined yet in 2000?
 

troncarver

Registered User.
Local time
Today, 00:49
Joined
Jan 31, 2006
Messages
14
foiled

ghudson,

I entered the function freplace into a module and then called it in a query but it will not open the query saying there is an ambigous name. What am I doing wrong?????
 

troncarver

Registered User.
Local time
Today, 00:49
Joined
Jan 31, 2006
Messages
14
foiled

ghudson,

I entered the function freplace into a module and then called it in a query but it will not open the query saying there is an ambigous name. What am I doing wrong?????
 

troncarver

Registered User.
Local time
Today, 00:49
Joined
Jan 31, 2006
Messages
14
alll GOOD in the HOOOD

program is done....thank you so much ghudson for your help....IT is awesome that there is a comprehensive programming community on the web that is willing to lend resources and time to complete strangers. Your services have not gone unnoticed and i again thank you very much !!!
 

Users who are viewing this thread

Top Bottom