473,666 Members | 2,238 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Adding Records using DAO and variables derived from queries.

I'm trying to write code that will automatically add a specified
number of records to a table using variables derived from queries. I
am attempting to do this with DAO.

Background.
I have three tables within an Access 2000 Database.
1. IssuedCards. It contains all of the card data for cards that have
been issued.

2. CardRequestTabl e. Used to hold user request for cards. This is
populated by the user.

3. temp. Used to store the last card to be processed from the last
request entered. This last card number is generated via a query that
looksup the last card issued in the IssuedCards table and adds however
many cards the user has requested from the CardRequestTabl e.

I am getting a "type mismatch" error in my loop statement. It is
telling me that a type mismatch exist between the variables card1 and
LastCard.

I have attempted this with the following code. Please forgive me, I
am very new to VBA. Thanks in advance.

Private Sub AddRecords()

Dim db As ADODB.Database
Dim rst As ADODB.Recordset
Dim card1 As ADODB.Recordset
Dim VendNum As ADODB.Recordset
Dim LastCard As ADODB.Recordset
Dim strSQLnextcard As String
Dim strSQLvend As String
Dim strSQLlastcard As String

strSQLnextcard = "SELECT TOP 1 FirstCard" & _
"FROM CardRequestTabl e" & _
"ORDER BY ID DESC;"
strSQLvend = "SELECT TOP 1 CardRequestTabl e.VendorNum" & _
"FROM CardRequestTabl e" & _
"ORDER BY CardRequestTabl e.ID DESC;"
strSQLlastcard = "SELECT Temp.LastCardNu m" & _
"FROM Temp;"
Set db = CurrentDb()
Set card1 = db.OpenRecordse t(strSQLnextcar d, dbOpenDynaset)
Set VendNum = db.OpenRecordse t(strSQLvend, dbOpenDynaset)
Set LastCard = db.OpenRecordse t(strSQLlastcar d, dbOpenDynaset)
Set rst = db.OpenRecordse t("IssuedCards" )

With rst
'Right below in the do while statment is where the type mismatch
occurs.
Do While card1 <= LastCard
.AddNew
![CardNum] = card1
![VendorNum] = VendNum
.Update
Loop
End With
End

End Sub
Nov 12 '05 #1
2 2015
> With rst
'Right below in the do while statment is where the type mismatch
occurs.
Do While card1 <= LastCard
.AddNew
![CardNum] = card1
![VendorNum] = VendNum
.Update
Loop
End With
End

End Sub


Card1 and VendNum are recordsets and have no values to equate to. You may
need to specify the field you want the value from.

![CardNum] = card1!FirstCard
![VendorNum] = VendNum!VendorN um
Mike Storr
www.veraccess.com

Nov 12 '05 #2
Excellent! Thanks Mike!
"Mike Storr" <no****@somewhe re.con> wrote in message news:<1y******* ************@ne ws20.bellglobal .com>...
With rst
'Right below in the do while statment is where the type mismatch
occurs.
Do While card1 <= LastCard
.AddNew
![CardNum] = card1
![VendorNum] = VendNum
.Update
Loop
End With
End

End Sub


Card1 and VendNum are recordsets and have no values to equate to. You may
need to specify the field you want the value from.

![CardNum] = card1!FirstCard
![VendorNum] = VendNum!VendorN um
Mike Storr
www.veraccess.com

Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
4322
by: tom | last post by:
I am new to SQL administration. >From a list of IDs that are the primary key in one table (i.e. Customer Table), I want to make changes in tables that use those IDs as a foreign key. Basically I want to say: If fk_ID is in list then do these statements to that record
6
2499
by: Robin S. | last post by:
**Eric and Salad - thank you both for the polite kick in the butt. I hope I've done a better job of explaining myself below. I am trying to produce a form to add products to a table (new products). Tables: tblCategoryDetails CategoryID SpecID
24
19900
by: clare at snyder.on.ca | last post by:
I have a SQL query I need to design to select name and email addresses for policies that are due and not renewed in a given time period. The problem is, the database keeps the information for every renewal in the history of the policyholder. The information is in 2 tables, policy and customer, which share the custid data. The polno changes with every renewal Renewals in 2004 would be D, 2005 S, and 2006 L. polexpdates for a given customer...
8
3266
by: shumaker | last post by:
I'm wondering if adding an autonumber primary key will improve the performance of a multiuser access database on a network share. I have a website that lists many tips for improving performance of access, but doesn't mention primary keys. However, it seems logical to think that having no primary key means that when a user updates a record, the database has to do comparisons on multiple fields to identify the specific record being...
6
2625
by: ninrulz | last post by:
I have created a database that has over 70 queries and over 40k records. I used the OutputTo action to export the queries to Excel. I would like the functionality of adding the date (Month-YY) to each of the Excel file names as they are exported. It seems that the OutputTo action only allows for predetermined names or a prompt for each file. I do not want to type the file names 70+ times and renaming each of the ..xls files afterwards is a...
8
1607
by: mantrid | last post by:
Hello Im having problems working out why the following code does not work. I dont think its the sql as the error occurs on the first update which ever one is put there ($q1 or $q2). Ive swapped then around to test this. Help greatly appreciated The error is Unknown column 'A' in 'field list' but there is no field 'A'. im thinking that the 'A' may be first letter of the word Array, as if it is using this as a variable, but i dont know...
11
2438
by: kaisersose1995 | last post by:
Hi, I've got an import procedure working, using a standard import specification to import a .csv file into a temporary table. The problem i'm having is that i have 4 different sets of borrower details on the same line e.g. B1-Title, B1-Initials, B1-Surname, B2-Title, B2-Initials, B2-Surname, etc. all linked to my main borrower table via an unique account number. My 1st append query matches which account numbers are new to the main...
8
2797
by: rbg | last post by:
I did use query plans to find out more. ( Please see the thread BELOW) I have a question on this, if someone can help me with that it will be great. In my SQL query that selects data from table, I have a where clause which states : where PermitID like @WorkType order by WorkStart DESC
1
2505
by: vbDavidC | last post by:
I am adding a new record to a table via a dataset/adapter. I have got the following to work for me but I am wondering if there is a better way to do this. I am having to have something in my DS before I can add records, since DS does not exist. I'd rather not have a SELECT since I really don't need any records in my dataset that I will be adding a new record to. Dim dsNewRow As DataRow
0
8440
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8866
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8550
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8638
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7381
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6191
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5662
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4193
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1769
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.