Dim MyConn as Object
Private Sub Connectdb ()
Set myconn = CreateObject ("ADODB. Connection ")-----> Create Connection object
Dim Str as String
str = "Driver={mysql ODBC 5.3 Unicode DRIVER};" & _----> Join statement ODBC Driver
"Server=localhost;" & _----> Host
"port=3306;" & _-----> Port number
"Database=test;" & _-----> Specify Database
"User=read;" & _------> Username
"Password=read;" & _------> Password
"Option=3"
MyConn.Open str----> Open connection
Dim SQL as String
Dim I as Integer
Dim field as String
-----------Cycle begins
For I=1 to 500
field = Worksheets ("Sheet4"). Cells (i, 5)---> Get query criteria from cells
sql = "Select Delivery_no from tb_table where tb_table.order_id = '" & Field & "'"-----> Stitching SQL
Sheets ("Sheet1"). Cells (i, 3). CopyFromRecordset myconn.execute (SQL)-----> Assign Query Results to Sheet1 3rd column
Next I
End of-------------cycle
Myconn.close-----> Close Connection
End Sub
Excel uses cell values to query the MySQL database and return data to the appropriate cells