KaiserSouza
Technical User
Hi,
I'm using a VB app to connect to an Access database via odbc. I'm trying to transfer data from one access database to another using 'company_name' as the index field for both tables. The problem is, company_name may contain special characters i.e. &, literal comma, etc. This is wreaking havoc to the sql statement i'm trying to pass. here's part of my code:
sql = "Select Company_Name from COMPANY"
objconn1.Open "DB1"
objrs1.Open sql, objconn1
objconn2.Open "DB2"
objrs1.MoveFirst
While Not objrs1.EOF
Set txtCompany.DataSource = objrs1
txtCompany.DataField = "company_name"
sql2 = "Select company.company_name, company.company_ID from company where (((company.Company_Name) =" & Chr(34) & Trim(txtCompany.Text) & Chr(34) & "));"
txtCID.Text = sql2
objrs2.Open sql2, objconn2
If Not objrs2.EOF Then
'this is where I will copy company_id from db2 to db1
End If
Wend
I've passed the string literal in sql2 in MS-Access' query wizard and the sql statement was accepted by access (I substituted the ascii values with proper characters of course.) If the company name is for example "Sanford & son, Co" The app dies a horrible death because of the comma and the apersand.
any help would be greatly appreciated.
Thanks!
I'm using a VB app to connect to an Access database via odbc. I'm trying to transfer data from one access database to another using 'company_name' as the index field for both tables. The problem is, company_name may contain special characters i.e. &, literal comma, etc. This is wreaking havoc to the sql statement i'm trying to pass. here's part of my code:
sql = "Select Company_Name from COMPANY"
objconn1.Open "DB1"
objrs1.Open sql, objconn1
objconn2.Open "DB2"
objrs1.MoveFirst
While Not objrs1.EOF
Set txtCompany.DataSource = objrs1
txtCompany.DataField = "company_name"
sql2 = "Select company.company_name, company.company_ID from company where (((company.Company_Name) =" & Chr(34) & Trim(txtCompany.Text) & Chr(34) & "));"
txtCID.Text = sql2
objrs2.Open sql2, objconn2
If Not objrs2.EOF Then
'this is where I will copy company_id from db2 to db1
End If
Wend
I've passed the string literal in sql2 in MS-Access' query wizard and the sql statement was accepted by access (I substituted the ascii values with proper characters of course.) If the company name is for example "Sanford & son, Co" The app dies a horrible death because of the comma and the apersand.
any help would be greatly appreciated.
Thanks!