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