473,395 Members | 1,689 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 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 1877

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

31
by: da Vinci | last post by:
OK, this has got to be a simple one and yet I cannot find the answer in my textbook. How can I get a simple pause after an output line, that simply waits for any key to be pressed to move on? ...
4
by: Chuck | last post by:
Hello, I have an Access XP database that has several fields. One of the fields is a text field and has an account number that is preceeded by a text character, like: F102354. Every account...
1
by: Chuck | last post by:
I have a question tht I'm sure someone out there can answer. A friend of mine has developed an Access application that is a very business specific (niche type of application). The application...
1
by: Chuck | last post by:
I have a query that uses the query with the critera set to . We I run the query the msgbox pops up asking for the name information to be entered, but on the top (blue background) of the message box...
2
by: Chuck | last post by:
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...
1
by: Chuck | last post by:
I appreciate any help!!! I have an application that has 4 different forms that display the same information except for the fact that they are fed from 4 different parameter queries. The 4...
1
by: WØCBF | last post by:
I have an Access application that was written in ver 2002. I have distributed the application to our other offices using the Developers Toolkit and installed a runtime version of Access. At that...
3
by: WØCBF | last post by:
I know this code has worked before but now appears to get a compile error. The code it seems to choke on line 12. I receive the following message and it highlights the "rst!" statement. Error...
1
by: WØCBF | last post by:
Greetings, I have a form that is bound to a table that has about 15 fields in it and all of the fields are displayed on the main form. I have 4 fields that will be updated and I want to write...
2
by: WØCBF | last post by:
I am trying to copy the information from a form into a table. I have tried running the sql code from a macro by using the command : This works and writes the work 'test' into the field name...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.