Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

working with database in vb

i'm learning vb. i wrote this but it's not working:
Private Sub Form_Load()
Form1.Show
Dim objData As Database
Dim tbl1 As customerInfo
Set objData = opendatabase("C:\Documents and Settings\admin\My Documents\homework\dip_term 1\vbp\study\nga's data.mdb", True, False)
For Each tbl1 In objData.customerInfo
Combo1.AddItem (tbl1.Name)
Next tbl1
End Sub
what is the "true, false" value at the back of set statement?
and why is it not working?
[499 byte] By [vanhelsing] at [2007-11-11 9:42:18]
# 1 Re: working with database in vb
First of all, how is it "not working?" Do you get an error message? What does it say?

Second, for details on the OpenDatabase statement (such as what the True and False parameters mean), highlight the word "OpenDatabase" in VB's code editor and press the F1 key. If online help is not available, do a Web search for the statement in question.

Finally, what are you trying to do? Do you want to list all of the names from a table named CustomerInfo in a combo box?
Phil Weber at 2007-11-11 17:23:55 >
# 2 Re: working with database in vb
thank you for answering :D i want to list all the item in customername column in table tbl1
vanhelsing at 2007-11-11 17:24:55 >
# 3 Re: working with database in vb
Try this:

Dim db As Database
Dim rs As Recordset

Set db = OpenDatabase(...)
Set rs = db.OpenRecordset("SELECT CustomerName FROM tbl1", dbOpenSnapshot)

Do Until rs.EOF
Combo1.AddItem rs!CustomerName
rs.MoveNext
Loop

rs.Close
db.Close
Phil Weber at 2007-11-11 17:25:55 >
# 4 Re: working with database in vb
your error is here :

For Each tbl1 In objData.customerInfo
Combo1.AddItem (tbl1.Name)
Next tbl1

how "Each tbl1" while it's only one tbl not a collection for example , same for "next tbl1" . you may need as Phil told u some thing make for u "For each item in tbl1" this statment isn't acceptable in programming but Phil's one make the synonyme .
Amahdy at 2007-11-11 17:26:50 >
# 5 Re: working with database in vb
i'm trying to help my friend to do her assignment about VB, can i help your email address so i can ask you about some basic things. this is my email: nga251092 at yahoo.com
vanhelsing at 2007-11-11 17:27:59 >
# 6 Re: working with database in vb
because i'm a student now so i'm using working model edition. does it have any problem with working with database? i can't use opendatabase command even if i follow exactly the code you gave me
vanhelsing at 2007-11-11 17:28:58 >
# 7 Re: working with database in vb
I don't mind contacting me by mail [and I'm sharing my yahoo ID] but I prefere that u ask here so every body can get assistance and the benefit be for everybody here ...

so u can ask here , post your code where u stoped... and we will help u continue isa.
you will also get more than one answer .
Amahdy at 2007-11-11 17:29:51 >
# 8 Re: working with database in vb
because i'm a student now so i'm using working model edition. does it have any problem with working with database? i can't use opendatabase command even if i follow exactly the code you gave me

I don't think it's a problem what do u do to open the database ? and what type of connection u use ? also check if u have put the good reference to your project .
Amahdy at 2007-11-11 17:31:02 >
# 9 Re: working with database in vb
even if i copy and paste the above code, when i compile the file, it still has error: user-defined type not defined. That mean no such type is database

Dim db As Database
Dim rs As Recordset

Set db = OpenDatabase(C:\Documents and Settings\Ha Thi Nga\Desktop\dung\dung.mdb)
Set rs = db.OpenRecordset("SELECT CustomerName FROM tbl1", dbOpenSnapshot)

Do Until rs.EOF
Combo1.AddItem rs!CustomerName
rs.MoveNext
Loop

rs.Close
db.Close
vanhelsing at 2007-11-11 17:31:58 >
# 10 Re: working with database in vb
You must add a reference in your project to Microsoft Data Access Objects.
Phil Weber at 2007-11-11 17:32:59 >
# 11 Re: working with database in vb
from the vb IDE :
project >> reference >> (in the white box scroll down) , check the "Microsoft DAO xxx"
xxx --> the version , u may find more than one version , choose the heighst one and that's all !
Amahdy at 2007-11-11 17:33:58 >
# 12 Re: working with database in vb
unfortunately, i still have the same problem
vanhelsing at 2007-11-11 17:34:58 >
# 13 Re: working with database in vb
even if i copy and paste the above code, when i compile the file, it still has error: user-defined type not defined. That mean no such type is database

Dim db As Database
Dim rs As Recordset

Set db = OpenDatabase(C:\Documents and Settings\Ha Thi Nga\Desktop\dung\dung.mdb)
Set rs = db.OpenRecordset("SELECT CustomerName FROM tbl1", dbOpenSnapshot)

Do Until rs.EOF
Combo1.AddItem rs!CustomerName
rs.MoveNext
Loop

rs.Close
db.Close
i got my problem:
Set db = OpenDatabase(C:\Documents and Settings\Ha Thi Nga\Desktop\dung\dung.mdb)

it should be like this: Set db = OpenDatabase("C:\Documents and Settings\Ha Thi Nga\Desktop\dung\dung.mdb", True, False, True)

but it has another problem: runtime error :" Could not find installable ISAM" what is that and how to debug?
vanhelsing at 2007-11-11 17:36:04 >