Programming

Programming questions? Ask a programmer for answers ASAP

Ask a Computer Expert,
Get an Answer ASAP!

I will not consider myself an expert vba programmer (self…

Customer Question
Good day I will not...

Good day
I will not consider myself an expert vba programmer (self taught) but have figured out a way to export data in csv format from an online database that we use for our member management system by using the API export call.
The problem arises when I import the data in Excel. Some of the fields delimits incorrectly when users have entered commas in the fields resulting in incorrect data in incorrect fields.
Another company that have done work for us on another project informed me that they do not save the file but export it directly to a database.
My question is as follows. I need code to write the csv file to a sql server express database or Microsoft access. I have never really worked with databases.
I installed sql express and access.
Would code like below (copied from a site) work to write the data into database.
Sub run()Dim conn As ADODB.ConnectionDim rs As ADODB.RecordsetDim sqlStr As StringDim dbFilePath As StringDim dbName As String
'This is the part where the data is downloaded as csv file and everything works
Dim WinHttpReq As Object
Set WinHttpReq = CreateObject("Microsoft.XMLHTTP")
WinHttpReq.Open "GET", myURL, False
WinHttpReq.sendmyURL = WinHttpReq.responseBody
If WinHttpReq.Status = 200 Then
Set oStream = CreateObject("ADODB.Stream")
oStream.Open
oStream.Type = 1
oStream.Write WinHttpReq.responseBody
oStream.SaveToFile ("C:\Mobile application downloads\All members profile data.csv"), 2
oStream.Close
'I would now save the data as csv file but instead I now want to write to database
'Would the code below work?dbName = "DbInjectorsCatalog"dbFilePath = "C:\Users\marcinchyl\Desktop\Marcin2\Projects\InjectorsCatalog\Admin\DbInjectorsCatalog.mdf"connStr = "Driver={SQL Server native Client 11.0};Server=(LocalDB)\v11.0;AttachDBFileName=" & dbFilePath & ";Database=" & dbName & ";Trusted_Connection=Yes"sqlStr = "Select * from Injectors"Set conn = New ADODB.Connectionconn.ConnectionString = connStrconn.OpenSet rs = conn.Execute(sqlStr)Do While Not rs.EOFDebug.Print rs!Numberrs.MoveNextLoop
rs.CloseSet rs = NothingEnd Sub

Technician's Assistant: Is your Excel file saved to cloud storage services like Dropbox, Google Drive, or OneDrive?

No the vba excel program runs on the local disk (c drive)

Technician's Assistant: Anything else you want the Microsoft Office Expert to know before I connect you?

No thanks

Submitted: 8 months ago.Category: Programming
Show More
Show Less
Ask Your Own Programming Question
Customer reply replied 8 months ago
The column names must be auto created according to the column names in the csv file.
After the initial data import I want to update the records according to a unique identifier and add new records.
Customer reply replied 8 months ago
I update my code as below which I think should be a lot closer to what it was.
Sub Test_API_CSV_File()
'This is the part where the API csv file is downloaded- this part works already
Dim WinHttpReq As Object
Set WinHttpReq = CreateObject("Microsoft.XMLHTTP")
WinHttpReq.Open "GET", myURL, False
WinHttpReq.sendmyURL = WinHttpReq.responseBody
If WinHttpReq.Status = 200 Then
Set oStream = CreateObject("ADODB.Stream")
oStream.Open
oStream.Type = 1
oStream.Write WinHttpReq.responseBody
'At this point I normally save the data as a csv file- this is where I want to bulk insert into a sql server
'Not sure if I can now open connection to sql server?
Dim conn As ADODB.Connection
Set conn = New ADODB.Connection
conn.Open "Provider=SQLOLEDB;Data Source=ALWYNS\SQLEXPRESS;Initial Catalog=Your membership;Integrated Security=SSPI;"
'Not sure if I can insert FROM WinHttpReq.responseBody? Will the code below automatically create the columns according to the names in the first row of the csv file? How will the column types be determined?strSQLQuery = "BULK INSERT dbo.Customers " & _
"FROM WinHttpReq.responseBody " & _
"WITH (FIRSTROW = 1, FIELDTERMINATOR = ',', " & _
"ROWTERMINATOR = '\n', TABLOCK)"
With oComm
.ActiveConnection = locConnection
.CommandType = adCmdText
.CommandText = strSQLQuery
.Execute
Set conn = Nothing
End With
Else
End If
End Sub
Answered in 2 days by:
11/27/2017
Programmer: George Sibiya, Computer Hardware Engineer replied 8 months ago
George Sibiya
George Sibiya, Computer Hardware Engineer
Category: Programming
Satisfied Customers: 368
Experience: PhD in Computer Science
Verified
Hi,
Welcome to justanswer and thank you for utilizing our services.
Apologies for the long wait. Please advice if you still need help on this.
Regards,
G
Ask Your Own Programming Question
Customer reply replied 8 months ago
Hi
I have established in the meantime that I can import the downloaded csv file by using the import wizard of the Microsoft SQL server management Studio 17 for a flat file. The problem with this is that for some reason I can only import 1000 records. I get an error message but when I delete record 1001 or import another csv file the same story. It imports the first 1000 records hundred percent.
I have also started to get the BULK INSERT function going but is struggling at the moment to specify either comma, double quote " " or "" ""as the FIELDTERMINATOR.
Also not exactly sure what the downloaded csv file from the API call ROWTERMINATOR is.
Once I have the initial data either imported or inserted by bulk import the idea is to update the data every 15 minutes- that is only the records that have changed or new records (according to the unique identifier)
Or do you think one should rather replace all the data every 15 minutes. I takes about ten minutes to execute the procedure.
I would still need vba code for this procedure.Regards
Alwyn
Customer reply replied 8 months ago
Hi
My internet connection is very poor at the moment. We should maybe do it later- the tower I am feeding off went down.
Customer reply replied 8 months ago
Hi
I am going to cancel the remote assistance but definitely still want you to help me with the above.
Programmer: George Sibiya, Computer Hardware Engineer replied 8 months ago

Ok thanks. I'll look into it and update you when ready

Ask Your Own Programming Question
Customer reply replied 8 months ago
Hi
My code at the moment which executes but then it has a problem with column 262 too long which means that either it is not properly picking up the FIELDTERMINATOR of comma example, example or double quote "example, example" or even double double quote"" "" or is not picking up the ROWTERMINATOR
Sub Test_API_CSV_File()
Dim strSQL As String
'Dim cnn As New ADODB.Connection
Dim conn As ADODB.Connection
Set conn = New ADODB.Connection
conn.Open "Provider=SQLOLEDB;Data Source=ALWYNS\SQLEXPRESS;Initial Catalog=Your membership;Integrated Security=SSPI;"strSQL = "BULK INSERT [All members profile data test6] " & _
"FROM 'C:\Download\Test.csv' " & _
"WITH (FIRSTROW = 2, FIELDTERMINATOR = ',', " & _
"ROWTERMINATOR = '\n', TABLOCK)"
Debug.Print strSQLconn.Execute strSQL
Debug.Print strSQLcnn.CloseSet cnn = Nothing' End With
End Sub
Customer reply replied 8 months ago
Hi George
Any feedback?
Programmer: George Sibiya, Computer Hardware Engineer replied 8 months ago

there is an error which halted me I'll update in approximately 4 hours

Ask Your Own Programming Question
Was this answer helpful?

How JustAnswer works

step-image
Describe your issueThe assistant will guide you
step-image
Chat 1:1 with a programmerLicensed Experts are available 24/7
step-image
100% satisfaction guaranteeGet all the answers you need
Ask ATLPROG Your Own Question
ATLPROG
ATLPROG
ATLPROG, Computer Software Engineer
Category: Programming
Satisfied Customers: 7,677
7,677 Satisfied Customers
Experience: MS in IT.Several years of programming experience in Java C++ C C# Python VB Javascript HTML

ATLPROG is online now

A new question is answered every 9 seconds

How JustAnswer works:

  • Ask an ExpertExperts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
  • Get a Professional AnswerVia email, text message, or notification as you wait on our site. Ask follow up questions if you need to.
  • 100% Satisfaction GuaranteeRate the answer you receive.

JustAnswer in the News:

Ask-a-doc Web sites: If you've got a quick question, you can try to get an answer from sites that say they have various specialists on hand to give quick answers... Justanswer.com.
JustAnswer.com...has seen a spike since October in legal questions from readers about layoffs, unemployment and severance.
Web sites like justanswer.com/legal
...leave nothing to chance.
Traffic on JustAnswer rose 14 percent...and had nearly 400,000 page views in 30 days...inquiries related to stress, high blood pressure, drinking and heart pain jumped 33 percent.
Tory Johnson, GMA Workplace Contributor, discusses work-from-home jobs, such as JustAnswer in which verified Experts answer people’s questions.
I will tell you that...the things you have to go through to be an Expert are quite rigorous.

What Customers are Saying:

My Expert answered my question promptly and he resolved the issue totally. This is a great service. I am so glad I found it I will definitely use the service again if needed.

One Happy CustomerNew York

Wonderful service, prompt, efficient, and accurate. Couldn't have asked for more. I cannot thank you enough for your help.

Mary C.Freshfield, Liverpool, UK

This expert is wonderful. They truly know what they are talking about, and they actually care about you. They really helped put my nerves at ease. Thank you so much!!!!

AlexLos Angeles, CA

Thank you for all your help. It is nice to know that this service is here for people like myself, who need answers fast and are not sure who to consult.

GPHesperia, CA

I couldn't be more satisfied! This is the site I will always come to when I need a second opinion.

JustinKernersville, NC

Just let me say that this encounter has been entirely professional and most helpful. I liked that I could ask additional questions and get answered in a very short turn around.

EstherWoodstock, NY

Thank you so much for taking your time and knowledge to support my concerns. Not only did you answer my questions, you even took it a step further with replying with more pertinent information I needed to know.

RobinElkton, Maryland

< Previous | Next >

Meet the Experts:

ATLPROG

ATLPROG

Computer Software Engineer

7,677 satisfied customers

MS in IT.Several years of programming experience in Java C++ C C# Python VB Javascript HTML

LogicPro

LogicPro

Computer Software Engineer

7,175 satisfied customers

Expert in C, C++, Java, DOT NET, Python, HTML, Javascript, Design.

unvadim

unvadim

Computer Software Engineer

1,168 satisfied customers

Good knowledge of OOP principles. 3+ years of programming experience with Java and C++. Sun Certified Java Programmer 5.0.

lifesaver

lifesaver

Computer Software Engineer

950 satisfied customers

Several years of intensive programming and application development experience in various platforms.

ehabtutor

ehabtutor

Computer Software Engineer

936 satisfied customers

Bachelor of computer science, 5+ years experience in software development, software company owner

TheDoctor

TheDoctor

Software Engineer

893 satisfied customers

M.S. in Internet Information Systems

The-PC-Guy

The-PC-Guy

Software Engineer

848 satisfied customers

Extensive Knowledge in PHP, MYSQL, CSS & Javascript

< Previous | Next >

Related Programming Questions
Hello, I am trying to get to a website that uses a CAPTCHA
2013 Excel VBA Lang. only Hello, I am trying to get to a website that uses a CAPTCHA challenge. I don't mind entering the CAPTCHA code, but I cannot seem to get through using Microsoft.XMLHTTP. So wha… read more
Bob Stephens-Doll
Bob Stephens-Doll
6 satisfied customers
VBA code for login MS Access to SQL Server. I need help with
VBA code for login MS Access to SQL Server. I need help with MS Access Visual Basic for Applications (VBA) and SQL Server Migration Assistant (SSMA). I have our MS Access 2007/2010 database split into… read more
Richard
Richard
IT Manager
IT Manager, Consultant
3,474 satisfied customers
I am trying to insert a variable in SQL but I keep getting
I am trying to insert a variable in SQL but I keep getting my code stopped. Can someone help. I did some research online and tried double quote method and it did not work.… read more
Russell H.
Russell H.
Computer Technology Consultant
Vocational, Technical or Trade Scho
792 satisfied customers
How can I import a .csv file into an Access table OKPR35211
How can I import a .csv file into an Access table that just updates specified fields rather than append rows or create a new table.… read more
Richard
Richard
IT Manager
IT Manager, Consultant
3,474 satisfied customers
How do you convert an excel data table into a SQL database?
How do you convert an excel data table into a SQL database? Can this be done using VBA code? Please provide code examples. Thanks!… read more
Steve The IT Guy
Steve The IT Guy
Master\u0027s Degree
54 satisfied customers
Trying to use a dbgrid in VB6. Have created a dataconnection
Trying to use a dbgrid in VB6. Have created a dataconnection but getting ar error message 'IMO10 [Microsoft][ODBC Driver Manager] Data source name too long'. I've made the path and name as short as po… read more
Dave
Dave
44 satisfied customers
I am trying to import a csv file into an MS Access mdb table
I am trying to import a csv file into an MS Access mdb table in my Windows App using Visual Basic. There error I get is Syntax error (missing operator) in query expression '@[email protected]' linked to the last lin… read more
NY Eng
NY Eng
Control Systems Engineer
Bachelor\u0027s Degree
19 satisfied customers
VB Script to loop data? I want to get all data including columns
VB Script to loop data? I want to get all data including columns from the SQL table. Is there a easier way to do this? Dim objRS Set objRS=CreateObject("ADODB.Recordset") Set objRS = objCN.Execute(str… read more
SDSU_GURU
SDSU_GURU
58 satisfied customers
Hi I am trying to store uploaded file paths in a sql database
Hi I am trying to store uploaded file paths in a sql database using vb.net. The file uploads but I can't get it to write to the db. The code I have so far is as follows: Any help would be most appreci… read more
Tom
Tom
Systems Analyst
Bachelor\u0027s Degree
1 satisfied customers
Need to find a way to export Access data to Excel. each time
Need to find a way to export Access data to Excel. each time the database is ran the names of # XXXXX tabs needed to export to excel will change. for examepe if i run it today there may be 2 tabs name… read more
Suryanto
Suryanto
Computer Engineer
Bachelor's Degree
535 satisfied customers
I want to send a sql string to Oracle and fetch a recordset
I want to send a sql string to Oracle and fetch a recordset using VBA - using the code to sift through the set and compile what I need and return the results to a function call. This is very normal in… read more
Suryanto
Suryanto
Computer Engineer
Bachelor's Degree
535 satisfied customers
How do you post an appointment to Outlook from VB.NET How
How do you post an appointment to Outlook from VB.NET? How do you read info from SQL about the prospective appointment using VB.NET?… read more
Ingo U
Ingo U
Master\u0027s Degree
358 satisfied customers
Please can anyone help... Im sure I succeeded with the
Please can anyone help... I'm sure I succeeded with the code below at first ,but now i just can't get passed the error 1064 message below. I'm sure I've got the database and table access and strcuture… read more
Eljon
Eljon
Software Developer Consultant
Associate Degree
562 satisfied customers
I have an access database with linked tables to Oracle. I
I have an access database with linked tables to Oracle. I am using excel vba to query this access database. I keep getting prompted for the Oracle user id and password, which I want to code in my conn… read more
Suryanto
Suryanto
Computer Engineer
Bachelor's Degree
535 satisfied customers
I found this tip on writing to MS-Access from MS-Excel VBA
I found this tip on writing to MS-Access from MS-Excel VBA macro, but it doesn't get past the cn.Open step (I am using MS-Office 2007): ' exports data from the active worksheet to a table in an Access… read more
NY Eng
NY Eng
Control Systems Engineer
Bachelor\u0027s Degree
19 satisfied customers
How do I connect VBasic 6 to Access 2007 I have upgraded
How do I connect VBasic 6 to Access 2007? I have upgraded my Access databases to 2007 and, surprise, surprise my VBasic programs no longer connect ("Unrecoginzed database format")… read more
Arty
Arty
Senior Administrator
Bachelor\u0027s Degree
469 satisfied customers
I have a select statement against an Oracle db to identify
I have a select statement against an Oracle db to identify files (with full file path). I need to build an executable that will access the db, return the file list, and then copy the identified files … read more
bryanh77
bryanh77
Software Engineer
Bachelor\u0027s Degree
67 satisfied customers
I am using excel vba 2003, and I want to use microsoft query
I am using excel vba 2003, and I want to use microsoft query to extract data to my workbook from a closed workbook by making the closed workbook a database. What I did was: - 1.on the current workbook… read more
Karl Everest King
Karl Everest King
Web Designer, Programmer
Vocational, Technical or Trade Scho
224 satisfied customers
Disclaimer: Information in questions, answers, and other posts on this site ("Posts") comes from individual users, not JustAnswer; JustAnswer is not responsible for Posts. Posts are for general information, are not intended to substitute for informed professional advice (medical, legal, veterinary, financial, etc.), or to establish a professional-client relationship. The site and services are provided "as is" with no warranty or representations by JustAnswer regarding the qualifications of Experts. To see what credentials have been verified by a third-party service, please click on the "Verified" symbol in some Experts' profiles. JustAnswer is not intended or designed for EMERGENCY questions which should be directed immediately by telephone or in-person to qualified professionals.

Disclaimer: Information in questions, answers, and other posts on this site ("Posts") comes from individual users, not JustAnswer; JustAnswer is not responsible for Posts. Posts are for general information, are not intended to substitute for informed professional advice (medical, legal, veterinary, financial, etc.), or to establish a professional-client relationship. The site and services are provided "as is" with no warranty or representations by JustAnswer regarding the qualifications of Experts. To see what credentials have been verified by a third-party service, please click on the "Verified" symbol in some Experts' profiles. JustAnswer is not intended or designed for EMERGENCY questions which should be directed immediately by telephone or in-person to qualified professionals.

Show MoreShow Less

Ask Your Question

x