global variables and function calls

global variables and function calls

Post by alen djoshabe » Tue, 03 Feb 1998 04:00:00



    can you set a database object to a certain filename in one form as
so:

    Dim datab as Database 'global ariable for this form

        Private Sub Form_Load()
            Set datab = OpenDatabase("Bsdb.mdb")
        End Sub

        Public Function getData() 'function to return datab object to be
call from other forms
            getData = datab
        End Function

and say i want to do a query in another form using this database
object.  why can't i just do like so, in a seperate form:

    Private Sub txtPass_KeyPress(KeyAscii As Integer)
    Dim code As String
    Dim record As Recordset
    Dim dat As Database

    If KeyAscii = vbKeyReturn Then

        code = txtPass.Text
        code = "'" + code + "'"
        frmMainData.getData dat
        Set record = dat.OpenRecordset("Select * from STAFF where
Database_code = " + code)
        If record.RecordCount > 0 Then
            lblLastStaff.Caption = record("Last_name")
            lblFirstStaff.Caption = record("First_name")

        Else
            MsgBox "Incorect Staff Code", vbOKOnly + vbExclamation,
"StaffID"

        End If

    End If

End Sub

when I try to do this, it returns an error message that it says "Item
not found in this collection"
Any ideas???
thanks in advance,
    danny

 
 
 

global variables and function calls

Post by Richard Magea » Wed, 04 Feb 1998 04:00:00


umm. i think your leaving out some important code! For example the your
function will not work as expected:
        Public Function getData() 'function to return datab object
            'getData = datab

            'it should be

            Set getData = datab
        End Function

Then when you want to reference it from another form you would do like so:

dim db as database

set db = frmMain.getData()

good luck!

        can you set a database object to a certain filename in one form as
so:

        Dim datab as Database 'global ariable for this form
            Private Sub Form_Load()
                Set datab = OpenDatabase("Bsdb.mdb")
            End Sub

            Public Function getData() 'function to return datab object to be
call from other forms
                getData = datab
            End Function

    and say i want to do a query in another form using this database object.
why can't i just do like so, in a seperate form:

        Private Sub txtPass_KeyPress(KeyAscii As Integer)
        Dim code As String
        Dim record As Recordset
        Dim dat As Database

        If KeyAscii = vbKeyReturn Then

            code = txtPass.Text
            code = "'" + code + "'"
            frmMainData.getData dat
            Set record = dat.OpenRecordset("Select * from STAFF where
Database_code = " + code)
            If record.RecordCount > 0 Then
                lblLastStaff.Caption = record("Last_name")
                lblFirstStaff.Caption = record("First_name")

            Else
                MsgBox "Incorect Staff Code", vbOKOnly + vbExclamation,
"StaffID"

            End If

        End If

    End Sub

    when I try to do this, it returns an error message that it says "Item
not found in this collection"
    Any ideas???
    thanks in advance,
        danny

 
 
 

1. REPEAT: Error using Global Variable in function call

Darren,

For some reason I cannot read you response from
yesterdays post. I get "Message Unavailable".

Thanks again

Pete
===================================================

My Transform Data Task include the following"

select  round(datediff(Day, ?, inv_date),0) as calc_days,
inv_date, from inv,customer
where  inv_customerkey = customer_key

When I select Parameters, I get an error message:

Error Source : Microsoft OLE DB DB Provider for ODBC
Drivers

Error Description: Microsoft [ODBC Driver]Invalid
Descriptor Index. Invalid parameter number

When I select Parse Query, I get "Incorrect Syntax near
the keyword SET"

Note that if I replace the ? with a valid date, it works
fine.

Thanks,
Pete

.

2. CA mailing list

3. Error using Global Variable in a function call

4. My Oracle connection is timing out?

5. DTS VB custom task reading a global variable and modifying a global variable

6. How to convert Rows into a string

7. calling global variables dynamically using VBScript

8. Win95 & sys(0),getenv

9. Creating a global variable for a filename and calling it from dtsrun

10. access R4GL global variables from C function

11. Q: C-functions and RDS and global Variables

12. Global variables in User-Defined Functions

13. DTS: Calling a global function