472,114 Members | 1,472 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,114 software developers and data experts.

<<HELP>> Problem with recalling a record and displaying it on the form!

I am trying to retrive one field from the "company info" table that
contains several fields but I want the "company name" field. There is
only one record in this table. When I entered the code below (which I
copied out of a book). I get the following error. The hickup comes in
the "dim db as database" line. However if I comment this out. It
doesn't like the next line either.

I appreciate any help you can give me. Also is this a problem between
ADO and DAO?

Error I receive is:

Microsoft Visual Basic
! Compile Error:
User-defined type not defined

Private Sub Form_Load()

Dim db as database
Dim rst as recordset
Dim strsql as string
Dim coname as string

Set db = currentdb
strsql = "select [company name] from [company info]"
set rst=db.openrecordset(strsql)
rst.movelast
rst.movefirst
coname=rst!("company name")
me.txtcompanyname = coname
rst.close
Set rst = nothing
Set db = nothing

End Sub

Thanks for all your help in advance!

Chuck
Nov 12 '05 #1
2 1789

"Chuck" <w0***@yahoo.com> wrote in message
news:64**************************@posting.google.c om...
I am trying to retrive one field from the "company info" table that
contains several fields but I want the "company name" field. There is
only one record in this table. When I entered the code below (which I
copied out of a book). I get the following error. The hickup comes in
the "dim db as database" line. However if I comment this out. It
doesn't like the next line either.

I appreciate any help you can give me. Also is this a problem between
ADO and DAO?
Almost certainly. This code is DAO. You very likely don't have a reference
to DAO set. Go to Tools->References to set it. Personally, I don't like to
mix DAO and ADO code in the same project, I would also uncheck the reference
to ADO.

Randy
Error I receive is:

Microsoft Visual Basic
! Compile Error:
User-defined type not defined

Private Sub Form_Load()

Dim db as database
Dim rst as recordset
Dim strsql as string
Dim coname as string

Set db = currentdb
strsql = "select [company name] from [company info]"
set rst=db.openrecordset(strsql)
rst.movelast
rst.movefirst
coname=rst!("company name")
me.txtcompanyname = coname
rst.close
Set rst = nothing
Set db = nothing

End Sub

Thanks for all your help in advance!

Chuck

Nov 12 '05 #2
"Randy Harris" <ra***@SpamFree.com> wrote in message news:<YP*******************@newssvr16.news.prodigy .com>...
"Chuck" <w0***@yahoo.com> wrote in message
news:64**************************@posting.google.c om...
I am trying to retrive one field from the "company info" table that
contains several fields but I want the "company name" field. There is
only one record in this table. When I entered the code below (which I
copied out of a book). I get the following error. The hickup comes in
the "dim db as database" line. However if I comment this out. It
doesn't like the next line either.

I appreciate any help you can give me. Also is this a problem between
ADO and DAO?


Almost certainly. This code is DAO. You very likely don't have a reference
to DAO set. Go to Tools->References to set it. Personally, I don't like to
mix DAO and ADO code in the same project, I would also uncheck the reference
to ADO.

Randy
Error I receive is:

Microsoft Visual Basic
! Compile Error:
User-defined type not defined

Private Sub Form_Load()

Dim db as database
Dim rst as recordset
Dim strsql as string
Dim coname as string

Set db = currentdb
strsql = "select [company name] from [company info]"
set rst=db.openrecordset(strsql)
rst.movelast
rst.movefirst
coname=rst!("company name")
me.txtcompanyname = coname
rst.close
Set rst = nothing
Set db = nothing

End Sub

Thanks for all your help in advance!

Chuck


Thanks Randy,

This seems to have cleared up alot. I guess from the DAO version you
can't use the "me." reference for the open form?

Thanks Again,
Chuck
Nov 12 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

31 posts views Thread by da Vinci | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.