[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:
Private Sub Form_Unload(Cancel As Integer)
If CN.Open > 0 Then
CN.Close
Set CN = Nothing
End If
End Sub
'and
Private Sub Form_Unload(Cancel As Integer)
If CN.Open = True Then
CN.Close
Set CN = Nothing
End If
End Sub
'and
Private Sub Form_Unload(Cancel As Integer)
If Len(CN.Open) > 0 Then
CN.Close
Set CN = Nothing
End If
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...
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
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.
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. :D
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.
Re: [RESOLVED] Is there a cn.open = true command?
Yes, each thread should be on a single issue/problem/topic. :)
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!