A
Amanda
I am a novice at vb and am having difficulty getting this working. I have
named the fields in excel and am trying to map the data to appropriate
fields in SQL.
I have a connection to the database and it does export successfully...
except it exports all null values which means I am not mapping the fields
correctly. I have pasted what I have written... What am I missing??
Sub AddRecord()
'Dimension Variables
Dim conn 'Holds the Database Connection Object
Dim rsAdd 'Holds the RecordSet for the New Record to be Added
Dim strconn As String
Dim sSQL
'Database Connection
strconn = "Driver={SQL
Server};SERVER=FEX01;UID=sa;PWD=;DATABASE=Noetic_Coupons"
Set conn = CreateObject("adodb.connection")
Set rsAdd = CreateObject("adodb.recordset")
sSQL = "Select * FROM coupon"
rsAdd.CursorType = 2
rsAdd.LockType = 3
rsAdd.Open sSQL, strconn
rsAdd.AddNew
Range("couponnumber") = rsAdd.Fields("coupnumber")
Range("Width") = rsAdd.Fields("coupwidth")
Range("thickness") = rsAdd.Fields("coupthickness")
Range("ultimatewidth") = rsAdd.Fields("coupultimatewidth")
Range("ultimatethickness") = rsAdd.Fields("coupultimatethickness")
Range("fracturewidth") = rsAdd.Fields("coupfracturewidth")
Range("fracturethickness") = rsAdd.Fields("coupfracturethickness")
Range("length") = rsAdd.Fields("couplength")
Range("fracturelength") = rsAdd.Fields("coupfracturelength")
Range("gaugelength") = rsAdd.Fields("coupgaugelength")
Range("gaugefracturelength") = rsAdd.Fields("coupgaugefracturelength")
Range("yieldstrain02") = rsAdd.Fields("coupyieldstrain")
Range("yieldextens") = rsAdd.Fields("coupyieldextension")
Range("ultimatestress") = rsAdd.Fields("coupultimatestress")
Range("ultimatestrain") = rsAdd.Fields("coupultimatestrain")
Range("yoveru") = rsAdd.Fields("coupYoverU")
Range("fracturestrain") = rsAdd.Fields("coupfracturestrain")
Range("Yield_02") = rsAdd.Fields("coupyield")
Range("fractureextens") = rsAdd.Fields("coupfractureextension")
Range("fractureload") = rsAdd.Fields("coupfractureload")
Range("fracturearea") = rsAdd.Fields("coupfracturearea")
Range("reducedarea") = rsAdd.Fields("coupreducedarea")
Range("AreaReduction") = rsAdd.Fields("coupareareduction")
Range("elongation") = rsAdd.Fields("coupelongation")
Range("UltimateArea") = rsAdd.Fields("coupultimatearea")
Range("area") = rsAdd.Fields("couparea")
rsAdd.Update
End Sub
named the fields in excel and am trying to map the data to appropriate
fields in SQL.
I have a connection to the database and it does export successfully...
except it exports all null values which means I am not mapping the fields
correctly. I have pasted what I have written... What am I missing??
Sub AddRecord()
'Dimension Variables
Dim conn 'Holds the Database Connection Object
Dim rsAdd 'Holds the RecordSet for the New Record to be Added
Dim strconn As String
Dim sSQL
'Database Connection
strconn = "Driver={SQL
Server};SERVER=FEX01;UID=sa;PWD=;DATABASE=Noetic_Coupons"
Set conn = CreateObject("adodb.connection")
Set rsAdd = CreateObject("adodb.recordset")
sSQL = "Select * FROM coupon"
rsAdd.CursorType = 2
rsAdd.LockType = 3
rsAdd.Open sSQL, strconn
rsAdd.AddNew
Range("couponnumber") = rsAdd.Fields("coupnumber")
Range("Width") = rsAdd.Fields("coupwidth")
Range("thickness") = rsAdd.Fields("coupthickness")
Range("ultimatewidth") = rsAdd.Fields("coupultimatewidth")
Range("ultimatethickness") = rsAdd.Fields("coupultimatethickness")
Range("fracturewidth") = rsAdd.Fields("coupfracturewidth")
Range("fracturethickness") = rsAdd.Fields("coupfracturethickness")
Range("length") = rsAdd.Fields("couplength")
Range("fracturelength") = rsAdd.Fields("coupfracturelength")
Range("gaugelength") = rsAdd.Fields("coupgaugelength")
Range("gaugefracturelength") = rsAdd.Fields("coupgaugefracturelength")
Range("yieldstrain02") = rsAdd.Fields("coupyieldstrain")
Range("yieldextens") = rsAdd.Fields("coupyieldextension")
Range("ultimatestress") = rsAdd.Fields("coupultimatestress")
Range("ultimatestrain") = rsAdd.Fields("coupultimatestrain")
Range("yoveru") = rsAdd.Fields("coupYoverU")
Range("fracturestrain") = rsAdd.Fields("coupfracturestrain")
Range("Yield_02") = rsAdd.Fields("coupyield")
Range("fractureextens") = rsAdd.Fields("coupfractureextension")
Range("fractureload") = rsAdd.Fields("coupfractureload")
Range("fracturearea") = rsAdd.Fields("coupfracturearea")
Range("reducedarea") = rsAdd.Fields("coupreducedarea")
Range("AreaReduction") = rsAdd.Fields("coupareareduction")
Range("elongation") = rsAdd.Fields("coupelongation")
Range("UltimateArea") = rsAdd.Fields("coupultimatearea")
Range("area") = rsAdd.Fields("couparea")
rsAdd.Update
End Sub