Where To Write The Connection String

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chandru8
    New Member
    • Sep 2007
    • 145

    Where To Write The Connection String

    Hi everybody

    Can anyone suggest me where to write the connection string
    because am writing the connection string in each form load closing it in form_unload

    the problem is when i want to change the path mean i need to change the in change

    is there any alternative

    thanks in advance
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    write that in a module or can use the load event of MDI form for the purpose.

    Comment

    • chandru8
      New Member
      • Sep 2007
      • 145

      #3
      I Have Written The Connection Open In The Module
      For Executing The Query I Used Set Module1.rs = Connection.exec ute(string )

      Is It Correct

      NOW I TRIED WRITTING INT THE MDI FORM
      BUT THE QUERY WHICH I WROTE IN THE FORM IS NOT WORKING
      ------------------------MDI FORM
      DIM objCon As New ADODB.Connectio n
      DIM rs As New ADODB.Recordset
      DIM strSql As String

      Private Sub MDIForm_Load()
      objCon.Connecti onString = "Provider = Microsoft.jet.o ledb.4.0;Data source = C:\Crd.mdb"
      objCon.Open
      End Sub

      Private Sub MDIForm_Unload( Cancel As Integer)
      objCon.Close
      Set objCon = Nothing
      End Sub
      ------------------------FORM
      strSql = "SELECT * FROM Login INNER JOIN MappingStatus ON Login.UserName = MappingStatus.U sername WHERE (((Login.UserNa me)='" & txtUserName.Tex t & "'));"
      Set rs = objCon.Execute( strSql)

      Comment

      • debasisdas
        Recognized Expert Expert
        • Dec 2006
        • 8119

        #4
        declare the connection in module.

        open /close in form.

        remove the semicolon from SQL statement.

        Comment

        Working...