 |
| Access VBA Discuss using VBA for Access programming. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

August 9th, 2006, 12:09 AM
|
|
Authorized User
|
|
Join Date: Jul 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
double quotes in data - giving error in storage
Hi friends,
My project : reading a text file , storing the data in CSV file and then importing to MS access database
previously i had problem that my data contains comma . so the data was getting splitted while storing so i figured it out, like this
Data Input - 98,789
If InStr(strField, ",") <> 0 Then strField = Chr(34) & strField & Chr(34)
Char(34) = "
Data Output = "98,789
Stored in CSV and Database as 98,789
But now my problem is my data is
O"KEANE, JAMES
Data input = O"KEANE, JAMES
If InStr(strField, ",") <> 0 Then strField = Chr(34) & strField & Chr(34)
Data output = "O"KEANE, JAMES"
Stored in CSV and Database = Field 1 = OKEANE
Field 2 = JAMES"
i have used trim the space
I want it to be stored as O"KEANE, JAMES in Field 1
Can anybody help me with this ?
Thanks and Regards
Lawson, COBOL
__________________
Thanks and Regards
Lawson, COBOL
|
|

August 10th, 2006, 03:56 AM
|
|
Authorized User
|
|
Join Date: Jul 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
hi friends
i figured it out by myself
i divided the string into two eliminating double quotes and then concatinating two string and finally adding double quotes again to
whole new string and it works fine
Data input = O"KEANE, JAMES
If InStr(strField, Chr(34)) <> 0 Then
strfield1 = Trim(Mid(strField, 1, InStr(strField, Chr(34))))
' Data Output = O"
strfield2 = Trim(Mid(strField, InStr(strField, Chr(34)), 15))
' Data Output = "KEANE, JAMES
strField = strfield1 & strfield2
' Data Output = O""KEANE, JAMES
End If
If InStr(strField, ",") <> 0 Then strField = Chr(34) & strField & Chr(34)
If strField = "" Then strField = ""
'Data Output = ""O"KEANE, JAMES""
Stored in CSV as = O"KEANE, JAMES
Thanks and Regards
Lawson, COBOL
|
|

August 21st, 2006, 02:55 AM
|
|
Authorized User
|
|
Join Date: Jul 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi friends better way to handle any kind of character in the data is call the Para " Remove_any_char " by command Call Remove_any_char(Field)
Field - which has to be filtered
Char (34) = "
Sub Remove_any_char (strField)
Dim i As Integer
Dim strField1 As String
For i = 1 To Len(strField)
If Mid(strField, i, 1) = Chr(34) Then GoTo NextChar
strField1 = strField1 & Mid(strField, i, 1)
NextChar:
Next i
If strField1 <> "" Then
strField = strField1
strField = Chr(34) & strField & Chr(34)
End If
End Sub
Above code removes " in the data present anywhere
like wise we can check for
If Mid(strField, i, 1) = "-" Then GoTo NextChar
or
If Mid(strField, i, 1) = " " Then GoTo NextChar <- checks for space
or
If Mid(strField, i, 1) = "(" Then GoTo NextChar
Thanks and Regards
Lawson, COBOL
|
|
 |