VB6 dll

S

SalimShahzad

dear gurus,

I had written one dll file hereunder, just to perform the same actions
on all forms and i can call them from any where, means write once then
run everywhere:
+++++++++++++++++++++++++++++++++++++==
Public appAction As New Access.Application

Public Function ac_first()
appAction.DoCmd.GoToRecord , , acFirst
End Function
+++++++++++++++++++++++++++++++++++++

where on form i call like this:
+++++++++++++++++++++++++++++++++++++
Option Compare Database
Option Explicit

Dim objAction As Takaful.basAction

Private Sub btnFirst_Click()

Call objAction.ac_first

End Sub
+++++++++++++++++++++++++++++++++++++
now it does not works properly can any one helps me where i am doing a
mistake...basically i wanted to write all codes/logics/functions in dll
then call there... i had written other fucntions of calendar working
fine...but all action button using via com/automation giving me error
rgds,
shahzhad
 
N

Norman Yuan

I assume you use the ActiveX DLL in Access VBA (since you post in Access
NG). See comments inline.

SalimShahzad said:
dear gurus,

I had written one dll file hereunder, just to perform the same actions
on all forms and i can call them from any where, means write once then
run everywhere:
+++++++++++++++++++++++++++++++++++++==
Public appAction As New Access.Application

"Dim xxx As New Xxxxxx" is not good way. It is legal, but cause some
porblem, especially when you are not very careful. Some programmers simply
do not do it. They recommend

'First declare a reference variable
Dim xxx As Xxxxxx
......
'When the object instance is needed
Set xxx=New Xxxxx 'Now the object instance is created explicitly.

The reason I mention this is that youe two code snippets used two different
ways. Your problem here is that you SHOULD not declare "appAction" as New
Access.Application, nor you SHOULD not "Set appAction=New Access....", if
you did so somewhere in you "basAction" class. Since you use the class in
VBA, where the Access.Application is there already, working on a opened
*.mdb file, why do you create a new Access.Application (i.e. launching a new
Access session)? Did you open the same *.mdb file in the new Acess session
and call basAction methods in that new Access session? What you did is while
you are in an Access session, you automate another Access session.

In your case, you declare the "appAction" as reference to
Access.Application, and pass the running Access.Application reference to it
before you call any method in the class. In your VBA code, it looks like:

Dim objAction As basAction
Set objAction=New basAction
Set objAction.appAction=Application 'See note*
objAction.ac_first
....

Note*: Application is global variable in Access VBA that refers to
Access.Application, the running access session. While in your code, since
you declared appAction as New and did not use "Set appAction=New..."
statement, so, when the first time the appAction reference is used in
following code, a NEW Access.Application (session) is launched, but most
likely, it is invisible (by default, the Access.Application object instance
created programmatically is invisible, you can verify it using Task
Manager).

Public Function ac_first()
appAction.DoCmd.GoToRecord , , acFirst
End Function
+++++++++++++++++++++++++++++++++++++

where on form i call like this:
+++++++++++++++++++++++++++++++++++++
Option Compare Database
Option Explicit

Dim objAction As Takaful.basAction

Private Sub btnFirst_Click()

Call objAction.ac_first

Not sure whether the objAction has been instantiated or not. Before you call
a methode of objAction, you must create the object instance, either using

Dim xxx As New Xxxxx(not recommended),

or

Dim xxx As Xxxxx

Set xxx=New Xxxxx
 
S

SalimShahzad

Thanks you gurus,
what i am trying to do writing all business logics in .dll in module of
visual basic 6 from there i had add ms access reference to call the
access COM interface and access their properties...i had suceess little
bit but not 100%...as it has in shared mode acceess so does nt allow
any session to open

rest say you wants to put ur all coding via dll file then you call that
dll in ms access in reference.

i hope you got a clear idea what i am trying to do. now see this codes
this is module codes in visual basic 6
++++++++++++++++++==
Public Function f_Dtloan(dt_dob As Date, Dt_loan As Date) As Date
ageEntry = DateDiff("yyyy", "# & dt_dob & #", "# & Dt_loan & #")


End Function
Public Function f_DtMaturity(intLoanTerm As Integer, Dt_loan As Date)
dtMaturity = DateAdd("m", intLoadTerm, "# & Dt_loan & #")
End FunctionPublic Function f_Dtloan(dt_dob As Date, Dt_loan As Date)
As Date
ageEntry = DateDiff("yyyy", "# & dt_dob & #", "# & Dt_loan & #")
+++++++++++++++++
then when i try to as variable, object variable from form of access it
gives me zero results as it does not recognize this
i know there must be some small things to be fix here

rgds,
shahzad
 
D

Douglas J. Steele

Since dt_dob and Dt_loan are both defined as dates, you don't need to worry
about the # delimiters (which, as Mike pointed out, you've implemented
incorrectly)

ageEntry = DateDiff("yyyy", dt_dob, Dt_loan)

and

dtMaturity = DateAdd("m", intLoadTerm, Dt_loan)

is all you should need.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top