MyTable

My code below was Quoted by (emoreau) and it is work very well, However as I continue my project I need to transfer the table name  "Stocks_history" to another Database called G_History. The table below are all under the database "MyProject" since Stocks_history will now go separately to another database the code will no longer fucntion. How Can I Change the code? Please help me.
Private Sub cmdSave_click()
Dim i As Integer
Dim cn As ADODB.Connection
Call OPEN_CON(cn, "MyProject", "Winpos")
    For i = 1 To grid.Rows - 1
    Call save_Table(cn, grid.TextMatrix(i, 0), grid.TextMatrix(i, 1), grid.TextMatrix(i, 2))
Next
Set cn = Nothing
MsgBox "Done"
grid.Clear
End Sub
 
 
Public Sub save_Table(cn As ADODB.Connection, Pckcode As String, Desc As String, Deduct As Double)
Dim sql As String
sql = "SELECT SH2.ProCode, MAX(SH2.The_Date) AS The_Date " & _
          "into #Temp " & _
          "FROM stocks_History AS SH2 " & _
          "where SH2.procode in (SELECT M3.Procode FROM Myset AS M3 inner JOIN Package AS P3 on P3.GCode = M3.GCode and P3.Pckcode = '" & Pckcode & "' )" & _
          "GROUP BY SH2.ProCode " & _
          "insert into stocks_History(Procode, description, Outpro, Balance, The_date) " & _
          "select SH.Procode, SH.description, SH.outpro -  (M.Qty * " & Deduct & ") - (Sh.outpro), SH.Balance  - (M.Qty * " & Deduct & "), getdate() " & _
          "from stocks_History AS SH " & _
          "INNER JOIN #Temp AS X " & _
          "ON SH.ProCode = X.ProCode " & _
          "AND SH.The_Date = X.The_Date " & _
          "INNER JOIN Myset AS M " & _
          "ON M.Procode = SH.Procode " & _
          "inner JOIN Package AS P3 on P3.GCode = M.GCode and P3.Pckcode = '" & Pckcode & "' " & _
          "drop table #temp "
 
cn.Execute sql
End Sub

Open in new window

Whing Dela CruzAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

käµfm³d 👽Commented:
If I understand you correctly, you should need to change line 4 to

    Call OPEN_CON(cn, "G_History", "Winpos")
0
Whing Dela CruzAuthor Commented:
Hi! line no. 4 is Call OPEN_CON(cn, "MyProject", "Winpos") , the Database "Myproject" is not totaly changed but only  stocks_History  has been transfered to the Database Called "G_History" now therefore, there two database should i join togethere to call all tables. Can you show me how? it might be like this;
Private Sub cmdSave_click()
Dim i As Integer
Dim cn As ADODB.Connection
Call OPEN_CON(cn, "MyProject", "Winpos")
Call OPEN_CON(cn, "G_History", "Winpos")
' I dont know what's next to do!
Thanks
 
0
käµfm³d 👽Commented:
So do you want to have two database connections open at one time?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Whing Dela CruzAuthor Commented:
Yes sir\madam,
so that I could run the code. Can you help me solving this problem?
I hope you do! Thanks
0
Whing Dela CruzAuthor Commented:
Thanks for your comment!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.