Keep object in memory while is form is open (Post in Stack Overflow) (1 Viewer)

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 17:07
Joined
Feb 28, 2001
Messages
27,223
OK, what is the purpose of the post? You got some discussions and suggestions. Why did you post this here? Did something not work?
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 18:07
Joined
Feb 19, 2002
Messages
43,352
You have seriously overcomplicated this and besides userforms are different from Access forms.
 

Djblois

Registered User.
Local time
Today, 15:07
Joined
Jan 26, 2009
Messages
598
OK, what is the purpose of the post? You got some discussions and suggestions. Why did you post this here? Did something not work?
Because if you aren't getting answers in one forum it is good to ask in others but cross-posting is not a good practice. It is always suggested to just post the link so multiple people do not give the same answers.
 

Djblois

Registered User.
Local time
Today, 15:07
Joined
Jan 26, 2009
Messages
598
You have seriously overcomplicated this and besides userforms are different from Access forms.
How did I over complicate it? I called an object and initialized some properties. Then later in a second click event I tried to use those properties and the object is no longer in memory. If it is too complicated, tell me how you would have done it differently. I am here to learn.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 18:07
Joined
Feb 19, 2002
Messages
43,352
I wouldn't have used a class. Access forms are already classes. What was the purpose of making a class? Did it offer any reuse options or is it just for one specific task? What about the class makes it more "efficient" than standard code behind a bound form?

You need help from someone else. Not me. I see nothing in that code that screams "I need to be a class" to me. Creating procedures would have been just as effective in organizing the code. Looks to me like you made a class because you could and that isn't a reason in my book unless you are doing this for practice to teach yourself how to build classes. I would choose a more useful task, even just for practice.

You have to collect data from the user to make the renewal. Enter the data in a bound form, validate it in the form's BeforeUpdate event and let Access do the rest. That is simple and efficient and you aren't reinventing the wheel.

I can see that you know how to code but you are coding in Access. Do you know how to use bound forms? Do you know how to use the form and control events to ensure that only valid data gets saved? Do you know that a recordset is an object? Do you understand that the best way to use a RAD tool is to let it do its thing and not try to impose your will on it in a misguided attempt to make it "better".
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 18:07
Joined
May 21, 2018
Messages
8,554
So lets simplify to the relevant code

1. You have a custom class and instantiate it in the form click event
Code:
Public this_renewal As Renewal

Private Sub cmdMA_Click()
      Set this_renewal = Factory.CreateRenewal(cMA)
      'other code here
End Sub

we know that the class instantiates without problem. But when you try to reference it again you get an object variable not set.

2. We then try to use the instantiated object later but you get that it is not set.
Code:
Private Sub cmdImport_Click()
    strTableName = this_renewal.Table
End Sub

Before we start chasing our tails. "This_renewal" is declared and used in the same form module, and you are confident the below line is causing the error?
Code:
strTableName = this_renewal.Table
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 18:07
Joined
May 21, 2018
Messages
8,554
You confident this is not your true problem
Code:
 Call FixExcelFile

How about putting at the top of the method
Code:
msgbox this_renewal is nothing
msgbox this_renewal.table is nothing
 

Users who are viewing this thread

Top Bottom