Results 1 to 6 of 6

Thread: [RESOLVED] Data Environment connection problem

  1. #1

    Thread Starter
    Hyperactive Member Capp's Avatar
    Join Date
    May 2005
    Location
    Texas
    Posts
    409

    Resolved [RESOLVED] Data Environment connection problem

    Hey guys,
    I am using the DataEnvironment and DataReport to show a simple little printout.

    If I use the database connection wizard for the DataEnvironment, it connects just fine. But the problem is that when run from another system, the file path is different.

    I tried doing App.path method, but that didnt' work so I figured I would have to code the connection.

    This is the same bit of code you guys helped me with last week. Here is what I've got.

    I have a DataEnvironment called dePrint
    Inside that, I have a DEConnection called con1
    Inside that, I have a DECommand called Print

    My DataReport is called datPrint
    - The DataMember property is set to Print
    - The DataSource Property is set to dePrint

    VB Code:
    1. Private Sub cmdPrint_Click()
    2.  
    3.     Dim strDate As String
    4.     Dim strSQL As String
    5.  
    6. '   Make sure the connection isn't left open from last printing
    7.  
    8.     If dePrint.rsPrint.State = adStateOpen Then
    9.         dePrint.rsPrint.Close
    10.     End If
    11.  
    12. '   If I leave out these next 4 lines it works fine
    13.  
    14.     dePrint.con1.Provider = "Microsoft.Jet.OLEDB.4.0"
    15.     dePrint.con1.CursorLocation = adUseClient
    16.     dePrint.con1.Properties("Data Source") = App.Path & "\EmpLic.mdb"
    17.     dePrint.con1.Open
    18.    
    19. '   Get date information. This is what you guys helped me with and it works fine.
    20.  
    21.     strDate = "#" & Format(Now, "mm/dd/yyyy") & "#"
    22.     strSQL = "SELECT * FROM Licenses WHERE DateDiff(" _
    23.        & Chr(34) & "d" & Chr(34) _
    24.        & ", " & strDate & ", [LicenseExpires]) <= 30 ORDER BY EmpName"
    25.  
    26.    
    27. '   Open the report with the selected info. Works fine if left to default.    
    28.  
    29.     dePrint.rsPrint.Open strSQL
    30.     datPrint.WindowState = vbMaximized
    31.     datPrint.Show
    32.    
    33.    
    34. End Sub

    Under the DataEnvironment, I have the connection (con1). If I use the built-in wizard to select the database, it works fine, but I need it to be App.Path so it can work on any system.

    Any ideas where I screwed up or what I'm forgetting?

    Thanks
    AmazingAntivirus.com
    Remote Data Backups


    Please Mark your Thread "Resolved", if the query is solved...

    If a post has helped you then Please Rate it!

  2. #2

    Thread Starter
    Hyperactive Member Capp's Avatar
    Join Date
    May 2005
    Location
    Texas
    Posts
    409

    Re: Data Environment connection problem

    Interesting update:

    If I comment out the first few lines to make sure the connection is closed:

    VB Code:
    1. If dePrint.rsPrint.State = adStateOpen Then
    2.         dePrint.rsPrint.Close
    3.     End If

    It works just fine, but as soon as I close out the report and click print again, I get the error telling me it can't perform this while the connection is open.

    If I add .close to the end of the Sub, it errors out completely.

    What a pain
    AmazingAntivirus.com
    Remote Data Backups


    Please Mark your Thread "Resolved", if the query is solved...

    If a post has helped you then Please Rate it!

  3. #3

    Thread Starter
    Hyperactive Member Capp's Avatar
    Join Date
    May 2005
    Location
    Texas
    Posts
    409

    Re: Data Environment connection problem

    I think I figured it out. It seems to be working.

    Can someone double-check my code to make sure I didn't miss anything? It works fine on my pc, but I want to make sure it is going to jive on another system.


    VB Code:
    1. Private Sub cmdPrint_Click()
    2.  
    3.     If dePrint.rsPrint.State = adStateOpen Then
    4.         dePrint.rsPrint.Close
    5.     End If
    6.  
    7.     Dim strDate As String
    8.     Dim strSQL As String
    9.    
    10.     Call MainCon      'open connection to database
    11.     Set RS = New ADODB.Recordset
    12.  
    13.     strDate = "#" & Format(Now, "mm/dd/yyyy") & "#"
    14.     strSQL = "SELECT * FROM Licenses WHERE DateDiff(" _
    15.        & Chr(34) & "d" & Chr(34) _
    16.        & ", " & strDate & ", [LicenseExpires]) <= 30 ORDER BY EmpName"
    17.        
    18.     RS.Open strSQL, Con, adOpenStatic, adLockOptimistic
    19.    
    20.     dePrint.rsPrint.Open RS
    21.     datPrint.WindowState = vbMaximized
    22.     datPrint.Show
    23.    
    24.     RS.Close          'close recordset
    25.     Con.Close        'close connection
    26.  
    27. End Sub
    28.  
    29.  
    30.  
    31. Public Sub MainCon()
    32.  
    33.     Set Con = New ADODB.Connection
    34.     Con.CursorLocation = adUseClient
    35.     Con.Provider = "Microsoft.Jet.OLEDB.4.0"
    36.     Con.Properties("Data Source") = App.Path & "\EmpLic.mdb"
    37.     Con.Open
    38.  
    39. End Sub
    AmazingAntivirus.com
    Remote Data Backups


    Please Mark your Thread "Resolved", if the query is solved...

    If a post has helped you then Please Rate it!

  4. #4

    Thread Starter
    Hyperactive Member Capp's Avatar
    Join Date
    May 2005
    Location
    Texas
    Posts
    409

    Re: Data Environment connection problem

    That didn't fix it.

    Once I compile it and run it on a different machine, when I click the Print button, it still keeps trying to access the database from the original location.

    Here is the message box that appears. If I manually enter the path, it works for as long as the program is still running. If I shut it down and relaunch it, it goes back to this.

    Any ideas, based on the code above?

    Thanks
    Attached Images Attached Images  
    AmazingAntivirus.com
    Remote Data Backups


    Please Mark your Thread "Resolved", if the query is solved...

    If a post has helped you then Please Rate it!

  5. #5
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Data Environment connection problem

    The GUI wrapper of ADO is supposed to make things easy... if your going out of your way to make it work then I suggest you drop the point-and-click GUI and go straight to ADO code. Below has sample on how to show data report without using the data environment.

    http://www.vbforums.com/showthread.p...ataenvironment

    Do additional search for sample code on using/setting up the ADO connection object... you will only have to change the path info in the connection string before you open the connection.

  6. #6

    Thread Starter
    Hyperactive Member Capp's Avatar
    Join Date
    May 2005
    Location
    Texas
    Posts
    409

    Re: Data Environment connection problem

    Thank you for your help.

    That fixed it. I combined what you gave me with what I already had and got it to work without using a DataEnvironment.

    Kudos and thanks again
    AmazingAntivirus.com
    Remote Data Backups


    Please Mark your Thread "Resolved", if the query is solved...

    If a post has helped you then Please Rate it!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width