Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. CurrentDb Connection String...

CurrentDb Connection String...

Scheduled Pinned Locked Moved Database
questiondatabasebusinesshelptutorial
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    new_phoenix
    wrote on last edited by
    #1

    I would appreciate some info regarding how to connect to the currently open database using the CurrentDb connection string. I am not certain of the syntax. Here is what I have so far:

    Dim dbsHeadcount As Database
    Dim Cnxn As ADODB.Connection
    Dim strConn As String
    Dim rstInputFile As ADODB.Recordset
    Dim cmdSQLInputFile As ADODB.Command
    Dim strSQLInputFile As String
    Dim rstHyperionMany As ADODB.Recordset
    Dim cmdSQLHyperionMany As ADODB.Command
    Dim strSQLHyperionMany As String
    Dim rstHyperionOne As ADODB.Recordset
    Dim cmdSQLHyperionOne As ADODB.Command
    Dim strSQLHyperionOne As String
    Dim strDBPath As String
    Dim strFileName As String
    Dim strMessage As String
    
    Set dbsHeadcount = CurrentDb
    Set cmdSQLInputFile = New ADODB.Command   
    Set cmdSQLInputFile.ActiveConnection = CurrentDb.Connection   '  IS THIS RIGHT??? IF NOT WHAT IS THE SYNTAX??? :confused::confused::confused:
    strSQLInputFile = "SELECT \[COUNTRY\], \[TYPE\], \[BUSINESS UNIT\], " & \_
        "\[L/R/G\], \[REGION\], \[JOB FUNCTION\], \[09/12/2007 Reported\] " & \_
        "\[NUMINDEX\] FROM \[TBLINPUTFILE\]"
    cmdSQLInputFile.CommandType = adCmdText
    cmdSQLInputFile.CommandText = strSQLInputFile
    Set rstInputFile = cmdSQLInputFile.Execute()
    rstInputFile.MoveFirst
    
    Set cmdSQLHyperionMany = New ADODB.Command
    Set cmdSQLHyperionMany.ActiveConnection = CurrentDb.Connection
    strSQLHyperionMany = "SELECT \[COUNTRY\], \[TYPE\], \[BUSINESS UNIT\], " & \_
        "\[L/R/G\], \[REGION\], \[JOB FUNCTION\], \[09/12/2007 Reported\] " & \_
        "FROM \[tblInputFile\]"
    cmdSQLHyperionMany.CommandType = adCmdText
    cmdSQLHyperionMany.CommandText = strSQLHyperionMany
    Set rstHyperionMany = cmdSQLHyperionMany.Execute()
    rstHyperionMany.MoveFirst
    

    The problem is how do I connect to the CurrentDb.Connection that is currently active?

    D 1 Reply Last reply
    0
    • N new_phoenix

      I would appreciate some info regarding how to connect to the currently open database using the CurrentDb connection string. I am not certain of the syntax. Here is what I have so far:

      Dim dbsHeadcount As Database
      Dim Cnxn As ADODB.Connection
      Dim strConn As String
      Dim rstInputFile As ADODB.Recordset
      Dim cmdSQLInputFile As ADODB.Command
      Dim strSQLInputFile As String
      Dim rstHyperionMany As ADODB.Recordset
      Dim cmdSQLHyperionMany As ADODB.Command
      Dim strSQLHyperionMany As String
      Dim rstHyperionOne As ADODB.Recordset
      Dim cmdSQLHyperionOne As ADODB.Command
      Dim strSQLHyperionOne As String
      Dim strDBPath As String
      Dim strFileName As String
      Dim strMessage As String
      
      Set dbsHeadcount = CurrentDb
      Set cmdSQLInputFile = New ADODB.Command   
      Set cmdSQLInputFile.ActiveConnection = CurrentDb.Connection   '  IS THIS RIGHT??? IF NOT WHAT IS THE SYNTAX??? :confused::confused::confused:
      strSQLInputFile = "SELECT \[COUNTRY\], \[TYPE\], \[BUSINESS UNIT\], " & \_
          "\[L/R/G\], \[REGION\], \[JOB FUNCTION\], \[09/12/2007 Reported\] " & \_
          "\[NUMINDEX\] FROM \[TBLINPUTFILE\]"
      cmdSQLInputFile.CommandType = adCmdText
      cmdSQLInputFile.CommandText = strSQLInputFile
      Set rstInputFile = cmdSQLInputFile.Execute()
      rstInputFile.MoveFirst
      
      Set cmdSQLHyperionMany = New ADODB.Command
      Set cmdSQLHyperionMany.ActiveConnection = CurrentDb.Connection
      strSQLHyperionMany = "SELECT \[COUNTRY\], \[TYPE\], \[BUSINESS UNIT\], " & \_
          "\[L/R/G\], \[REGION\], \[JOB FUNCTION\], \[09/12/2007 Reported\] " & \_
          "FROM \[tblInputFile\]"
      cmdSQLHyperionMany.CommandType = adCmdText
      cmdSQLHyperionMany.CommandText = strSQLHyperionMany
      Set rstHyperionMany = cmdSQLHyperionMany.Execute()
      rstHyperionMany.MoveFirst
      

      The problem is how do I connect to the CurrentDb.Connection that is currently active?

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      In what context??? In this VBA code in Access?? It looks like it, but we have to be sure. I think you might be looking for something closer to this:

      Dim conn As ADODB.Connection
      Dim comm As New ADODB.Command
      Dim rs As New ADODB.Recordset
      Dim param As ADODB.Parameter

      Set conn = Application.CurrentProject.Connection
      comm.ActiveConnection = conn
      ...
      

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007

      N 1 Reply Last reply
      0
      • D Dave Kreskowiak

        In what context??? In this VBA code in Access?? It looks like it, but we have to be sure. I think you might be looking for something closer to this:

        Dim conn As ADODB.Connection
        Dim comm As New ADODB.Command
        Dim rs As New ADODB.Recordset
        Dim param As ADODB.Parameter

        Set conn = Application.CurrentProject.Connection
        comm.ActiveConnection = conn
        ...
        

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007

        N Offline
        N Offline
        new_phoenix
        wrote on last edited by
        #3

        Thanks, Dave!!!

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups