PDA

View Full Version : Urgent : How run BCP command using .bat/.vbs file from Excel VBA?



agarwaldvk
03-06-2012, 02:42 PM
Hi Everybody


Please treat this as an urgent request!

Does anyone know how to run the BCP command using VBA :-


bcp ea_network_accrual.dbo.net_meter format nul -f c:\deepak\FormatFileFromScript.fmt -c -Smpfinsd\stage -T


I can successfully run this on DOS command prompt. I was trying to test this using a .bat or .vbs file to be called using Shell.Run command from within an Excel VBA module, but it doesn't seem to work.

The above command is to create the format file. This h as already been done. What I actually want to do is to be able to run another BCP command to upload a whole stack of data using the previously created format file in to a SQL Server database table. I want to call the BCP command from within the Excel VBA module.

BCP obviously from the DOS console and I have been able to run from there successfully - both to create the format and also to upload the data using the previously created format file.


Any suggestions?



This is the code that I have :-



Sub RunBCP()
Set objShell = CreateObject("Wscript.Shell")
strBCP = "bcp ea_network_accrual.dbo.net_meter format nul -f c:\deepak\FormatFile_Script.fmt -c -Smpfinsd\stage -T"
objShell.Run strBCP, 1, True
End Sub


Best Regards



Deepak

BertD
02-03-2014, 08:58 AM
Has this been solved? I have the same issue and can't seem to find a solution.