none
How to run two sub in one sheet VBA ? RRS feed

  • Question

  • HI, I had write a two sub code in VBA cause the procedure is too large. the problem now is when running the program, the data show out will disappear after run the second sub, MAy i know how to solve it ? thank you. 

    Example 

    Public Sub RawData() Dim oConn As ADODB.Connection Dim strSQL, strSQL1, strSQL2, strSQL3, strSQL4, strSQL5, strSQL6, strSQL7, strSQL8, strSQL9, strSQL10, strSQL11, strSQL12, strSQL13, strSQL14, strSQL15 As String Dim qRS As New Recordset Dim CColor As Integer Dim Col As Integer ---- -- a lots a lots code -- --- End sub sub RawData1() Dim oConn As ADODB.Connection Dim strSQL16, strSQL17, strSQL18, strSQL19, strSQL20, strSQL21, strSQL22, strSQL23, strSQL24, strSQL25, strSQL26, strSQL27, strSQL28, strSQL29, strSQL30 As String Dim qRS As New Recordset Dim CColor As Integer Dim Col As Integer ----- --- ---a lots code ---- --- End sub ----QUery button--- Private Sub CommandButton1_Click() Call RawData Call RawData1 End Sub 

    Wednesday, December 12, 2012 8:11 AM

All replies

  • One by one:

    call RawData
    call RawData1

    but you should seperate tables this source.

    p.s.

    when you using declaration like this:

    dim strSQL14, strSQL15 As String
     

    1st of them strSQL14 is not a String - but Variant

    2nd is a string

    You should declare every single one.

    p.s.2

    Use VB format when you caste VBACode.


    Oskar Shon, Office System MVP

    Press if Helpful; Answer when a problem solved



    Wednesday, December 12, 2012 10:34 AM
    Answerer