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: 6 months ago.Category: Programming
Show More
Show Less
Ask Your Own Programming Question
Customer reply replied 6 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 6 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 6 months ago
George Sibiya
George Sibiya, Computer Hardware Engineer
Category: Programming
Satisfied Customers: 352
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 6 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 6 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 6 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 6 months ago

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

Ask Your Own Programming Question
Customer reply replied 6 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 6 months ago
Hi George
Any feedback?
Programmer: George Sibiya, Computer Hardware Engineer replied 6 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,131 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

800 satisfied customers

Extensive Knowledge in PHP, MYSQL, CSS & Javascript

< Previous | Next >

Related Programming Questions
When I copy and paste in Excel it freezes
When I copy and paste in Excel it freezes… read more
John D
John D
Bachelor Degree in Engineering
342 satisfied customers
How do I setup Excel Columns so that you only have preset options
How do I setup Excel Columns so that you only have preset options to enter into that cell. e.g. Column titled Location, when you click cell in that column it gives you drop down list of preset options… read more
John D
John D
Bachelor Degree in Engineering
342 satisfied customers
Excel solver with multiple target cells
How can I program an Excel solver to get more than one target cell? Here is what I have so far. The normal solver used this code (appeared to use it, since I looked into the editor): SolverOk SetCell:… read more
John D
John D
Bachelor Degree in Engineering
342 satisfied customers
When opening an Excel file created in 2003 in Excel 2016 the
when opening an Excel file created in 2003 in Excel 2016 the columns width changed … read more
Jeevan DSouza
Jeevan DSouza
Professor
PhD
6 satisfied customers
It started out with excel not working. So I was told to
it started out with excel not working. So I was told to uninstall Microsoft 365 and reinstall it. How do I do that … read more
Jason Jones
Jason Jones
AAS Information Technology
6,324 satisfied customers
Excel Office 365. Two days ago. My excel spreadsheets have
My excel spreadsheets have an exclamation point on them. They are very slow. … read more
Richard
Richard
IT Manager
IT Manager, Consultant
3,436 satisfied customers
Does this forum charge. It's excel formulas. Office 365. I
I run a report on projects once a week and in the report are dates in six columns. I need to write a formula that looks up a project I'd on the latest report look for it on the previous weeks report then look at the first if six cells to see if the dates have changed. If do I need to apply conditional formatting to highlight the change… read more
The-PC-Guy
The-PC-Guy
Software Engineer
Bachelor's Degree
800 satisfied customers
My office excel program does not work correctly. When I sum
my office excel program does not work correctly. When I sum a column then … read more
Pete
Pete
Engineer
Bachelor\u0027s Degree
1,130 satisfied customers
I can't open an excel spreadsheet in Microsaoft Office
I can't open an excel spreadsheet in Microsaoft Office Professional 2007 that I was working on this afternoon. … read more
Viet - Computer Tech
Viet - Computer Tech
Computer Technican
Bachelor\u0027s Degree
969 satisfied customers
I need an excel expert. Get me someone for 2016 excel
I need an excel expert JA: When did you last update Excel? Customer: get me someone for 2016 excel JA: Anything else you want the Microsoft Office Expert to know before I connect you? Customer: no… read more
Jason Jones
Jason Jones
AAS Information Technology
6,324 satisfied customers
I have office 2013 excel, word, and outlook on my computer.
I have office 2013 excel, word, and outlook on my computer. Something happened on my desktop and 2013 word's shortcut and program disappeared. I haven't found a way to bring the program and shortcut b… read more
Kamil Anwar
Kamil Anwar
IT Consultant / Systems Engineer
Bachelor\u0027s Degree
460 satisfied customers
My Microsoft Word and Excel app now require Office 365. They
My Microsoft Word and Excel app now require Office 365. They didn't when I installed the apps. I have them linked to Dropbox files. ???? … read more
Jinsmn
Jinsmn
Systems Administrator
Diplom
1,260 satisfied customers
I have MS office 365 on a macbook pro. Excel is not working.
I have MS office 365 on a macbook pro. Excel is not working. onr particular file keeps coming up with not enough memory and will repair itself but it has lost all the spreadsheet formatting. This is a… read more
Richard
Richard
IT Manager
IT Manager, Consultant
3,436 satisfied customers
Please how to roundup decimal places in excel complex funcitons
Please how to roundup decimal places in excel complex funcitons like imsum, imsub, imdiv or alike, thanks… read more
John D
John D
Bachelor Degree in Engineering
342 satisfied customers
Can I use excel to create exception reporting from 2 lists
Can I use excel to create exception reporting from 2 lists of data, downloaded from a mainframe system into an excel spreadsheet? The data consists of invoice numbers and costs.… read more
John D
John D
Bachelor Degree in Engineering
342 satisfied customers
"microsoft excel needs vba macro language support to complete
"microsoft excel needs vba macro language support to complete this action"… read more
John D
John D
Bachelor Degree in Engineering
342 satisfied customers
Excel 2013 having issues like this. There isn't enough
excel 2013 having issues like this. There isn't enough memory to complete this action. try using less data or closing other applications. to increase memory availability, consider using a 64-bit versi… read more
Richard
Richard
IT Manager
IT Manager, Consultant
3,436 satisfied customers
I have lost the Autosum function on my Excel spreadsheet. The
I have lost the Autosum function on my Excel spreadsheet. The icon is there but it has "greyed-out" and will not function when you ty to click on it.… read more
Alex
Alex
Sr. Software Engineer
Bachelor\u0027s Degree
332 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