473,396 Members | 1,895 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,396 software developers and data experts.

Recordset Error, [13] Type Mismatch

133 100+
The code below is receiving a [13] mismatch type as soon as it hits the statement of
Expand|Select|Wrap|Line Numbers
  1. Set rstSummary = CurrentDb.OpenRecordset("tblNJDOC")
Again, in need of FRESH EYES...thank you in advance for guidance.

Mary

Expand|Select|Wrap|Line Numbers
  1. Private Sub Create_tblNJDOC()
  2.  
  3. '*****************************************************************************************
  4. ' This sub routine builds a temporary table to store the desired dates extract
  5. '
  6. '******************************************************************************************
  7.  
  8.  
  9. On Error GoTo Err_Hndlr
  10.  
  11. Dim dbs As DAO.Database
  12. Dim rstTemp As DAO.Recordset
  13. Dim rstSummary As Recordset
  14. Dim strSQL As String
  15.  
  16. 'set variable values
  17. Set dbs = CurrentDb
  18.  
  19. strSQL = "SELECT NJDOC.ProductName, " & _
  20.                 "NJDOC.NDC_1, " & _
  21.                 "NJDOC.GPI, " & _
  22.                 "Count(NJDOC.Quantity) AS QuantitySummed, " & _
  23.                 "Sum(NJDOC.[Amount Billed]) AS AmountBilledSummed, " & _
  24.                 "Sum(NJDOC.AAC) AS SumOfAAC, Sum(NJDOC.BillFee) AS BillFeeSummed, " & _
  25.                 "Sum(NJDOC.[Cost Billed]) AS CostBilledSummed " & _
  26.         "FROM NJDOC " & _
  27.         "GROUP BY NJDOC.ProductName, " & _
  28.                 "NJDOC.NDC_1, NJDOC.GPI " & _
  29.         "ORDER BY NJDOC.ProductName;"
  30.  
  31.  
  32.  
  33. 'Delete temporary table
  34.   DoCmd.RunSQL "DROP TABLE tblNJDOC;"
  35.  
  36. 'Create temporary table
  37. CurrentDb.Execute ("CREATE TABLE tblNJDOC(ProductName VARCHAR(125), " & _
  38.                 "NDC_1 VARCHAR(75), " & _
  39.                 "GPI varchar(20), " & _
  40.                 "QuantitySummed currency, " & _
  41.                 "AmountBilledSummed currency, " & _
  42.                 "BillFeeSummed currency, " & _
  43.                 "CostBilledSummed currency)")
  44.  
  45. 'Bind rstTemp to the temporary table
  46. Set rstTemp = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset)
  47. Set rstSummary = CurrentDb.OpenRecordset("tblNJDOC")
  48.  
  49.  
  50.  '*********temp fields for writing records
  51. Dim strProductName_TEMP As String
  52. Dim strNDC_1_TEMP As String
  53. Dim strGPI_TEMP As String
  54. Dim strQuantitySummed_TEMP As Integer
  55. Dim strAmountBilledSummed_TEMP As Integer
  56. Dim strBillFeeSummed_TEMP As Integer
  57. Dim strCostBilledSummed_TEMP As Integer
  58.  
  59. Dim strNDC_1_Stack As String
  60.  
  61.  
  62. strFirstRec = "Yes"
  63. strProductName_TEMP = " "
  64. strNDC_1_TEMP = " "
  65. strGPI_TEMP = " "
  66. strQuantitySummed_TEMP = 0
  67. strAmountBilledSummed_TEMP = 0
  68. strBillFeeSummed_TEMP = 0
  69. strCostBilledSummed_TEMP = 0
  70.  
  71. 'Move the data into the temporary table
  72.  
  73. rstTemp.MoveFirst
  74.  
  75. Do While rstTemp.EOF = False
  76.     If strFirstRec = "Yes" Then
  77.         strFirstRec = "No"
  78.         strProductName_TEMP = rstTemp!ProductName
  79.         strNDC_1_TEMP = rstTemp!NDC_1
  80.         strGPI_TEMP = rstTemp!GPI
  81.         strQuantitySummed_TEMP = rstTemp!QuantitySummed
  82.         strAmountBilledSummed_TEMP = rstTemp!AmountBilledSummed
  83.         strBillFeeSummed_TEMP = rstTemp!BillFeeSummed
  84.         strCostBilledSummed_TEMP = rstTemp!CostBilledSummed
  85.      End If
  86.  
  87.     If rstTemp!ProductName = strProductName_TEMP Then
  88.         If rstTemp!NDC_1 = strNDC_1_TEMP Then
  89.             strNDC_1_Stack = strNDC_1_TEMP
  90.         Else
  91.             strNDC_1_Stack = strNDC_1_Stack + "/ " + rstTemp!NDC_1
  92.             rstTemp!NDC_1 = strNDC_1_TEMP
  93.         End If
  94.     Else
  95.       ' Write temp records to table
  96.         rstTemp.AddNew
  97.             rstSummary!ProductName = strProductName_TEMP
  98.             rstSummary!NDC_1 = strNDC_1_Stack
  99.             rstSummary!GPI = strGPI_TEMP
  100.             rstSummary!QuantitySummed = strQuantitySummed_TEMP
  101.             rstSummary!AmountBilledSummed = strAmountBilledSummed_TEMP
  102.             rstSummary!BillFeeSummed = strBillFeeSummed_TEMP
  103.             rstSummary!CostBilledSummed = strCostBilledSummed_TEMP
  104.         rstTemp.Update
  105.  
  106.         ' Move rst (record set) into the temp fields
  107.  
  108.         strProductName_TEMP = rstTemp!ProductName
  109.         strNDC_1_TEMP = rstTemp!NDC_1
  110.         strGPI_TEMP = rstTemp!GPI
  111.         strQuantitySummed_TEMP = rstTemp!QuantitySummed
  112.         strAmountBilledSummed_TEMP = rstTemp!AmountBilledSummed
  113.         strBillFeeSummed_TEMP = rstTemp!BillFeeSummed
  114.         strCostBilledSummed_TEMP = rstTemp!CostBilledSummed
  115.         ' move to next record set (rst)
  116.     End If
  117.  
  118.         rstTemp.MoveNext
  119. Loop
  120.  
  121. ' write last record
  122. rstSummary.AddNew
  123.     rstSummary!ProductName = strProductName_TEMP
  124.     rstSummary!NDC_1 = strNDC_1_Stack
  125.     rstSummary!GPI = strGPI_TEMP
  126.     rstSummary!QuantitySummed = strQuantitySummed_TEMP
  127.     rstSummary!AmountBilledSummed = strAmountBilledSummed_TEMP
  128.     rstSummary!BillFeeSummed = strBillFeeSummed_TEMP
  129.     rstSummary!CostBilledSummed = strCostBilledSummed_TEMP
  130. rstSummary.Update
  131.  
  132. rstTemp.Close
  133. rstSummary.Close
  134.  
  135.  
  136. Create_tblNJDOC_Exit:
  137.   Exit Sub
  138.  
  139.  
  140. Err_Hndlr:
  141.     MsgBox "[" & Err.Number & "]:  " & Err.Description, vbInformation, "Create_tblNJDOC()"
  142.  
  143.  
Oct 12 '10 #1
5 2407
Mariostg
332 100+
dowlingm815, you really need to pay attention to your code, before an admin tells you...
You create table tblNJDOC yet your Select query refers to NJDOC.

Also why do you bother to Set dbs=currentDB if you don't use it (line 17, 37)
Oct 12 '10 #2
dowlingm815
133 100+
NJDOC is the name of the table that needs to be re-formatted into a new table. therefore, there are two separate NJDOC tables, one, import, the second, create, via tblNJDOC.

in regard to dbs=currentDB, i believe i need due to the fact that an imported table is being called.
Oct 12 '10 #3
MMcCarthy
14,534 Expert Mod 8TB
mariostg is correct, you set dbs = currentdb and then don't use it, you just use currentdb at line 17 and 37 instead of dbs. However, this would not cause your error.

I would add a DoEvents command after you create the table and before you try to put it in a recordset.

Expand|Select|Wrap|Line Numbers
  1. CurrentDb.Execute ("CREATE TABLE tblNJDOC(ProductName VARCHAR(125), " & _ 
  2.                 "NDC_1 VARCHAR(75), " & _ 
  3.                 "GPI varchar(20), " & _ 
  4.                 "QuantitySummed currency, " & _ 
  5.                 "AmountBilledSummed currency, " & _ 
  6.                 "BillFeeSummed currency, " & _ 
  7.                 "CostBilledSummed currency)") 
  8.  
  9. DoEvents
  10.  
  11. 'Bind rstTemp to the temporary table 
  12. Set rstTemp = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset) 
  13. Set rstSummary = CurrentDb.OpenRecordset("tblNJDOC") 
This will insure that tblNJDOC is created before you try to use it.

Mary
Oct 13 '10 #4
ADezii
8,834 Expert 8TB
Why DELETE then RE-CREATE the Temporary Table for each Call of the Sub-Routine? Simple CREATE the Temp Table once, then at each Call to the Routine, DELETE all the Records, then perform your APPEND Operation to it.
Oct 13 '10 #5
dowlingm815
133 100+
so by not setting dbs = currentDB, vba will assume it is the current database in use?
Oct 13 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: mujaqo | last post by:
I have a table consist of two fields UserID and Password, and a form with unbounded fields txtUserID and txtPassword. I’m running the below code on MS Access 2000 and I’m getting Run-time error...
5
by: Accessguest | last post by:
I've been given an Access DB for debugging. When running a query for a report the code stops with "Run time error 13 Type mismach". The code is stopping on the Else clause c =...
2
by: skundu | last post by:
Hi, I have just joined. I am getting a message when I am running a macro - run time error '13', type mismatch. when I am debuggung it it opens up my VBA code and shows this: Sub Updategraph()...
10
by: jasperz01 | last post by:
Hello, I'm kind of new to VBA and Access, so please forgive me if I'm doing stuff all wrong: I have the following code wich gives me a Error 13 Type Mismatch: Dim db As Database, rs...
14
by: gilsygirl | last post by:
Hello everyone Am having this error an just dont know what to do. Am using vb 6 and access database This is my code code vb: Public db As Database Public rs As Recordset
4
by: JFKJr | last post by:
Hello everyone, the following code is working fine for the first time when I run it and giving "Run-time error '13': Type mismatch" at line #15 during the second time and so on.... The code is...
1
by: Greg (codepug | last post by:
Solution Note: I am experimenting with an excellent popup calendar I found on the Allen Browne web site. I was receiving the following error (Error 13: Type mismatch) when clicking a button...
2
rhitam30111985
by: rhitam30111985 | last post by:
HI all , I am using Windows 2000 OS for out server . We use a VB tool to deploy all the COM applications. In that , this is a snippet of code that is failing : Option Explicit Dim...
5
by: Knowlton | last post by:
I am trying to set the value of a varible using DLookup and keep getting a type mismatch error. Here is what I have: Dim lngPickupTrailer As Long 'get mileage where trailer was picked up...
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:
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
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,...

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.