Results 1 to 7 of 7

Thread: [RESOLVED] Is there a cn.open = true command?

  1. #1

    Thread Starter
    Lively Member Brian M.'s Avatar
    Join Date
    Nov 2006
    Location
    Moberly MO
    Posts
    94

    Resolved [RESOLVED] Is there a cn.open = true command?

    Hello again. Ok, everthing is coming along well, but if I run my program and close it before I make a connection, I get a Object Variable or With block variable not set. I tried to use:

    VB Code:
    1. Private Sub Form_Unload(Cancel As Integer)
    2. If CN.Open > 0 Then
    3.     CN.Close
    4.     Set CN = Nothing
    5. End If
    6.  
    7. End Sub
    8.  
    9. 'and
    10.  
    11. Private Sub Form_Unload(Cancel As Integer)
    12. If CN.Open = True Then
    13.     CN.Close
    14.     Set CN = Nothing
    15. End If
    16.  
    17. End Sub
    18.  
    19. 'and
    20.  
    21. Private Sub Form_Unload(Cancel As Integer)
    22. If Len(CN.Open) > 0 Then
    23.     CN.Close
    24.     Set CN = Nothing
    25. End If
    26.  
    27. End Sub

    to see if the connection string was open, and close it if it was and if not then exit the program without trying to close something that is not open. They all error, if there is no connection. I need to find a way to make the program not error when user(me) clicks the trapclose without connecting first. It works fine if I establish a connection first. If you need me to, I can post the code I have so far. But it is getting a bit lengthy at this point so if you know what I am refering to, then I won't have to use unneccessary space. Thanks again. I will get through this eventually. I am just learning here...

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Re: Is there a cn.open = true command?

    Just check the state of the connection object.

    Code:
    If TypeName(cn) <> "Nothing" Then
        If cn.State = adStateOpen Then
            cn.Close
        End If
        Set cn = Nothing
    End If
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Lively Member Brian M.'s Avatar
    Join Date
    Nov 2006
    Location
    Moberly MO
    Posts
    94

    Re: Is there a cn.open = true command?

    Thanks!! That works perfectly... I apologize for the frequency of my posts, but as I said above I am learning as I write this app. When I am done I will definatly share it, I think you guys will like it.

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Re: Is there a cn.open = true command?

    We dont mind at all if you post a bunch As long as you dont post duplicates or spam then its all good.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    Lively Member Brian M.'s Avatar
    Join Date
    Nov 2006
    Location
    Moberly MO
    Posts
    94

    Re: Is there a cn.open = true command?

    Ok I will mark this one a resolved, when I get to another block I will start another thread. I think thats how I am supposed to do it. If not let me know. All my posts thus far have been for different problems I have run into.

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Re: [RESOLVED] Is there a cn.open = true command?

    Yes, each thread should be on a single issue/problem/topic.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7

    Thread Starter
    Lively Member Brian M.'s Avatar
    Join Date
    Nov 2006
    Location
    Moberly MO
    Posts
    94

    Re: [RESOLVED] Is there a cn.open = true command?

    I just want to say thanks for the time you guys take out of your busy schedules to answer these posts. I wouldn't be where I am at on this program and my vb knowledge right now if it wasn't for you guys helping me out. So, thanks!

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