Solved

MyTable

Posted on 2009-07-15
5
280 Views
Last Modified: 2013-11-25
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

0
Comment
Question by:Whing Dela Cruz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 75

Expert Comment

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

    Call OPEN_CON(cn, "G_History", "Winpos")
0
 

Author Comment

by:Whing Dela Cruz
ID: 24865784
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
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 24869268
So do you want to have two database connections open at one time?
0
 

Author Comment

by:Whing Dela Cruz
ID: 24869336
Yes sir\madam,
so that I could run the code. Can you help me solving this problem?
I hope you do! Thanks
0
 

Author Closing Comment

by:Whing Dela Cruz
ID: 31603983
Thanks for your comment!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question