i have getting an error called datasource name not found in
please help me out
Option Explicit
'Public strconn As String
Public projCode, batchCode, batchID, prdTblName
Public dbConn As New ADODB.Connection
Public Const strConn = "Provider=MSDASQL.1;Password=1234;Persist Security Info=True;User ID=root;Data Source=mySQL32;Initial Catalog=wds"
Sub init()
projCode = ""
batchCode = ""
UserForm1.Show
End Sub
Sub dbConnect()
Dim strConn As String
Dim dbConn As New ADODB.Connection
strConn = "Provider={MySQL ODBC 5.2 Unicode Driver};Password=1234;Persist Security Info=True;User ID=root;Data Source=wds;Initial Catalog=wds"
' strConn = "DSN=wds;DESCRIPTION=data;SERVER=localhost;UID=root;PWD=1234;DATABASE=wds;PORT=3306"
strConn = "Provider=MSDASQL.1;Password=1234;Persist Security Info=True;User ID=root;Data Source=wds;Initial Catalog=wds"
'dbConn.Open dsn = mySQL_UserDSN
dbConn.Open strConn
If dbConn.State = adStateOpen Then
MsgBox "Connected"
Else
MsgBox "DB Connection Failed"
End If
dbConn.Close
End Sub
Sub updateData()
Dim totColumns, totRows, i, j, WDS_id
Dim prBatchName, prTableQry, inTableQry, prTableQry1, dbQry
Dim rs As New ADODB.Recordset
Sheet1.Activate
'prBatchName = "tblProd_AGR_007"
totColumns = ActiveSheet.Cells(2, 1).CurrentRegion.Columns.Count
totRows = ActiveSheet.Cells(2, 1).CurrentRegion.Rows.Count
prBatchName = ActiveSheet.Cells(2, totColumns + 1).ID
dbConn.Open strConn
rs.Open "select * from " & prBatchName, dbConn, adOpenStatic, adLockOptimistic
For j = 3 To totRows
WDS_id = ActiveSheet.Cells(j, 1)
rs.Find "WDS_ID=" & WDS_id
For i = 2 To totColumns
rs(ActiveSheet.Cells(2, i).ID) = ActiveSheet.Cells(j, i)
Next
rs.Update
Next
rs.Close
dbConn.Close
MsgBox "Data updated sucessfully"
End Sub
Sub downloadData()
Dim i ', prdTblName
'prdTblName = "tblProd_" & projCode & "_" & batchCode
Dim qryStr, dataStr As String
Dim strConn As String
qryStr = "SELECT * FROM tblbatch_headers where idBatch= " & batchID & " order by col_seq asc"
Dim rs As New ADODB.Recordset
dbConn.Open strConn
rs.Open qryStr, dbConn, 3, 1
i = 0
Do While rs.EOF = False
i = i + 1
If i = 1 Then
dataStr = rs("tblColName")
Else
dataStr = dataStr & ", " & rs("tblColName")
End If
rs.MoveNext
Loop
' FP = For Prodction, IQR = In Process Quality Rejected, PC = Production Complete
' IQA = In Quality Check Approved, FQA = Final Quality Review Approved, FQR = Final Qaulity Review Rejected
qryStr = "SELECT " & dataStr & " FROM " & prdTblName & " where FQR_User_Code='" & Application.UserName & _
"' and line_status in('QP') order by line_status"
Sheet1.Activate
Sheet1.Columns.Clear
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:="ODBC;DSN=mySQL32;" _
, Destination:=Range("$A$2")).QueryTable
.CommandText = qryStr
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
' .SourceConnectionFile = _
"C:\Users\SwamyXPS15\Documents\My Data Sources\wds.odc"
' .ListObject.DisplayName = "Table_wds"
.Refresh BackgroundQuery:=False
End With
Range("C2").Select
rs.MoveFirst
i = 0
Do While rs.EOF = False
Dim rng As Range
i = i + 1
ActiveSheet.Cells(1, i) = rs("Comments")
ActiveSheet.Cells(2, i) = rs("ActualColName")
ActiveSheet.Cells(2, i).ID = rs("tblColName")
rs.MoveNext
Loop
ActiveSheet.Cells(2, i + 1).ID = prdTblName
rs.Close
dbConn.Close
MsgBox "Data downloaded sucessfully"
Unload UserForm1
End Sub
Function thisBatchId(strBatch As String) As Boolean
Dim SQLStr
Dim rs As New ADODB.Recordset
Dim strConn As String
If InStr(1, strBatch, ".", vbTextCompare) <= 0 Then
thisBatchId = False
' UserForm1.ListBox1.AddItem strBatch & " is an Invalid project/batch code .."
Exit Function
End If
projCode = Left(strBatch, InStr(1, strBatch, ".", vbTextCompare) - 1)
batchCode = Right(strBatch, InStr(1, strBatch, ".", vbTextCompare) - 2)
If dbConn.State = adStateClosed Then dbConn.Open strConn
SQLStr = "select b.idtblProjBatches batchId from tblprojects a, tblprojbatches b where" & _
" a.project_code='" & projCode & "' and b.idProject = a.idtblProjects " & _
" And b.batch_code='" & batchCode & "'"
rs.Open SQLStr, dbConn, adOpenStatic, adLockOptimistic
If rs.BOF = False Then
batchID = rs(0)
thisBatchId = True
rs.Close
dbConn.Close
prdTblName = "tblProd_" & projCode & "_" & batchCode
downloadData
Else
thisBatchId = False
rs.Close
dbConn.Close
' UserForm1.ListBox1.AddItem strBatch & " is an Invalid project/batch code .."
End If
'MsgBox Rs.RecordCount
End Function
please help me out
Option Explicit
'Public strconn As String
Public projCode, batchCode, batchID, prdTblName
Public dbConn As New ADODB.Connection
Public Const strConn = "Provider=MSDASQL.1;Password=1234;Persist Security Info=True;User ID=root;Data Source=mySQL32;Initial Catalog=wds"
Sub init()
projCode = ""
batchCode = ""
UserForm1.Show
End Sub
Sub dbConnect()
Dim strConn As String
Dim dbConn As New ADODB.Connection
strConn = "Provider={MySQL ODBC 5.2 Unicode Driver};Password=1234;Persist Security Info=True;User ID=root;Data Source=wds;Initial Catalog=wds"
' strConn = "DSN=wds;DESCRIPTION=data;SERVER=localhost;UID=root;PWD=1234;DATABASE=wds;PORT=3306"
strConn = "Provider=MSDASQL.1;Password=1234;Persist Security Info=True;User ID=root;Data Source=wds;Initial Catalog=wds"
'dbConn.Open dsn = mySQL_UserDSN
dbConn.Open strConn
If dbConn.State = adStateOpen Then
MsgBox "Connected"
Else
MsgBox "DB Connection Failed"
End If
dbConn.Close
End Sub
Sub updateData()
Dim totColumns, totRows, i, j, WDS_id
Dim prBatchName, prTableQry, inTableQry, prTableQry1, dbQry
Dim rs As New ADODB.Recordset
Sheet1.Activate
'prBatchName = "tblProd_AGR_007"
totColumns = ActiveSheet.Cells(2, 1).CurrentRegion.Columns.Count
totRows = ActiveSheet.Cells(2, 1).CurrentRegion.Rows.Count
prBatchName = ActiveSheet.Cells(2, totColumns + 1).ID
dbConn.Open strConn
rs.Open "select * from " & prBatchName, dbConn, adOpenStatic, adLockOptimistic
For j = 3 To totRows
WDS_id = ActiveSheet.Cells(j, 1)
rs.Find "WDS_ID=" & WDS_id
For i = 2 To totColumns
rs(ActiveSheet.Cells(2, i).ID) = ActiveSheet.Cells(j, i)
Next
rs.Update
Next
rs.Close
dbConn.Close
MsgBox "Data updated sucessfully"
End Sub
Sub downloadData()
Dim i ', prdTblName
'prdTblName = "tblProd_" & projCode & "_" & batchCode
Dim qryStr, dataStr As String
Dim strConn As String
qryStr = "SELECT * FROM tblbatch_headers where idBatch= " & batchID & " order by col_seq asc"
Dim rs As New ADODB.Recordset
dbConn.Open strConn
rs.Open qryStr, dbConn, 3, 1
i = 0
Do While rs.EOF = False
i = i + 1
If i = 1 Then
dataStr = rs("tblColName")
Else
dataStr = dataStr & ", " & rs("tblColName")
End If
rs.MoveNext
Loop
' FP = For Prodction, IQR = In Process Quality Rejected, PC = Production Complete
' IQA = In Quality Check Approved, FQA = Final Quality Review Approved, FQR = Final Qaulity Review Rejected
qryStr = "SELECT " & dataStr & " FROM " & prdTblName & " where FQR_User_Code='" & Application.UserName & _
"' and line_status in('QP') order by line_status"
Sheet1.Activate
Sheet1.Columns.Clear
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:="ODBC;DSN=mySQL32;" _
, Destination:=Range("$A$2")).QueryTable
.CommandText = qryStr
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
' .SourceConnectionFile = _
"C:\Users\SwamyXPS15\Documents\My Data Sources\wds.odc"
' .ListObject.DisplayName = "Table_wds"
.Refresh BackgroundQuery:=False
End With
Range("C2").Select
rs.MoveFirst
i = 0
Do While rs.EOF = False
Dim rng As Range
i = i + 1
ActiveSheet.Cells(1, i) = rs("Comments")
ActiveSheet.Cells(2, i) = rs("ActualColName")
ActiveSheet.Cells(2, i).ID = rs("tblColName")
rs.MoveNext
Loop
ActiveSheet.Cells(2, i + 1).ID = prdTblName
rs.Close
dbConn.Close
MsgBox "Data downloaded sucessfully"
Unload UserForm1
End Sub
Function thisBatchId(strBatch As String) As Boolean
Dim SQLStr
Dim rs As New ADODB.Recordset
Dim strConn As String
If InStr(1, strBatch, ".", vbTextCompare) <= 0 Then
thisBatchId = False
' UserForm1.ListBox1.AddItem strBatch & " is an Invalid project/batch code .."
Exit Function
End If
projCode = Left(strBatch, InStr(1, strBatch, ".", vbTextCompare) - 1)
batchCode = Right(strBatch, InStr(1, strBatch, ".", vbTextCompare) - 2)
If dbConn.State = adStateClosed Then dbConn.Open strConn
SQLStr = "select b.idtblProjBatches batchId from tblprojects a, tblprojbatches b where" & _
" a.project_code='" & projCode & "' and b.idProject = a.idtblProjects " & _
" And b.batch_code='" & batchCode & "'"
rs.Open SQLStr, dbConn, adOpenStatic, adLockOptimistic
If rs.BOF = False Then
batchID = rs(0)
thisBatchId = True
rs.Close
dbConn.Close
prdTblName = "tblProd_" & projCode & "_" & batchCode
downloadData
Else
thisBatchId = False
rs.Close
dbConn.Close
' UserForm1.ListBox1.AddItem strBatch & " is an Invalid project/batch code .."
End If
'MsgBox Rs.RecordCount
End Function