database connection error - need assistance please

Is "Session" in scope? Try opening a message box that shows "session.Cashier.Name" - if that line errors out your variable "session" is out of scope. I would suspect this is the problem.

Reply to
Glenn Adams [MVP - Retail Mgmt]
Loading thread data ...

You have to pass it as a reference to your Function. This is pretty basic programming stuff - I hope you are testing thoroughly and taking frequent back-ups.

Public Function MyFunction(ByRef mySession as object) as boolean

'Do stuff with mySession msgbox("Cashier Name: " & mySession.Cashier.Name)

MyFunction = true end function

Reply to
Glenn Adams [MVP - Retail Mgmt]

Glenn, I do have a reference to session in my Process function, in the class module I've created for this project:

Public Function Process(ByRef session As Object) As Boolean Dim posSession As Object Set posSession = session With posSession.Transaction 'all my code End With Process = True End Function

I didn't realize that was not enough - I do not have any reference to session in any of the form modules that are also part of this project. So what you are saying is that I also need to include this in those as well? I guess I'm unclear as to how I pass this reference in my Form_Load event sub in my form module

I'm sorry for beating a dead horse, I just want to make sure that I not only get this working (hopefully) but that I also understand what's going on. I'll be the first to admit that this level of programming is fairly new to me, which is why, as you suggested, I have been making regular backups and working in a test copy of my project in a test database :) So I hope you don't give up on me, I really think I'm close, just need to finish this off. I do appreciate your helping me out.

Thank you, Kevin

"Glenn Adams [MVP - Retail Mgmt]" wrote:

Reply to
kskinne

That helped a lot Glenn thank you, I am learning that's for sure. I will definitely continue reading up on scope and variable declaration in the help file.

I guess I was assuming that if my Process function was public, then the session object i referred to there would be available everywhere in my app, but i was wrong.

Based on what you said, I think it's just as easy for me to take my two lines of code:

the line where I am assigning a query string to my glbsqlstr variable, and the line where I am using the OpenRecordset function

and place them in my Process function in my class module, instead of having them in my form_load sub. This way they will be set properly at the time my Process function is triggered by my hook. I believe that should work assuming my syntax for the OpenRecordset function is correct as I'm using it.

Thank you for helping me with this Glenn,

Kevin

"Glenn Adams [MVP - Retail Mgmt]" wrote:

Reply to
kskinne

Every variable has a certain SCOPE, depending on where and how it is declared.

For instance: Public Function Process(ByRef session As Object) as Boolean 'The parameter "session" can be used as a variable ONLY WITHIN THE Process() FUNCTION

msgbox session.Cashier.Name 'Will return the cashier's name

MySub1

MySub2 session

Process = True End Function

Private Sub MySub1()

msgbox session.Cashier.Name 'Will not return anything, because 'session' does not exist in this Sub

End Sub

Private Sub MySub2( ByRef mySession as Object)

msgbox mySession.Cashier.Name 'Will return the cashiers name, because mySession was passed a reference to the session Object

End Sub

You should search the VB Help system for "Scope" or "Scope of variables". Declaring variables in modules vs. classes vs. Forms will also affect their scope. Note that Forms are a special type of Class and you can give them PROPERTIES just as you can with a class.

Reply to
Glenn Adams [MVP - Retail Mgmt]

BeanSmart website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.