Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hair Loss and VB Events

Status
Not open for further replies.

Guru2B

Programmer
May 24, 2000
77
GB
Hi!

I'm pulling my hair out over this one. It's probably one of those 'duh...why didn't I see that before' moments, but here goes:

I have a treeview that displays all the records in a DB. When a node is clicked, it populates a class which in turn is displayed on the form for the user to view or modify.

I am using a SaveChanges method which writes all the data back to the class and then calls Class.Save().

The problem is this: If I try to put the SaveChanges in the Node_click event (save the current record before showing the next record), the SaveChanges causes an error because there is no existing class.

Is there any way to do this without losing any more of my hair?
 
No existing class? Are you creating several instances of that class at run time, or is there only one?

If there's only one, you need to create an instance kindof like this:

Set TempClass = New cMyClass

If you have an array of classes (or you don't want to SaveChanges on the first click), you could try this:

If TempClass(Index) Is Nothing Then
'first click, object variable not set
Else
TempClass(Index).SaveChanges
End If

Hopefully some combination of these 2 xmplz will help you keep what's left of your hair!

-Mike
Difference between a madman and a genius:
A madman uses his genius destructively,
A genius uses his madness constructively.
 
Thanks Mike. I had tried that method before, but I guess my syntax was waaaaay wrong. Thanks tons.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top