The code below is receiving a [13] mismatch type as soon as it hits the statement of - Set rstSummary = CurrentDb.OpenRecordset("tblNJDOC")
Again, in need of FRESH EYES...thank you in advance for guidance.
Mary -
Private Sub Create_tblNJDOC()
-
-
'*****************************************************************************************
-
' This sub routine builds a temporary table to store the desired dates extract
-
'
-
'******************************************************************************************
-
-
-
On Error GoTo Err_Hndlr
-
-
Dim dbs As DAO.Database
-
Dim rstTemp As DAO.Recordset
-
Dim rstSummary As Recordset
-
Dim strSQL As String
-
-
'set variable values
-
Set dbs = CurrentDb
-
-
strSQL = "SELECT NJDOC.ProductName, " & _
-
"NJDOC.NDC_1, " & _
-
"NJDOC.GPI, " & _
-
"Count(NJDOC.Quantity) AS QuantitySummed, " & _
-
"Sum(NJDOC.[Amount Billed]) AS AmountBilledSummed, " & _
-
"Sum(NJDOC.AAC) AS SumOfAAC, Sum(NJDOC.BillFee) AS BillFeeSummed, " & _
-
"Sum(NJDOC.[Cost Billed]) AS CostBilledSummed " & _
-
"FROM NJDOC " & _
-
"GROUP BY NJDOC.ProductName, " & _
-
"NJDOC.NDC_1, NJDOC.GPI " & _
-
"ORDER BY NJDOC.ProductName;"
-
-
-
-
'Delete temporary table
-
DoCmd.RunSQL "DROP TABLE tblNJDOC;"
-
-
'Create temporary table
-
CurrentDb.Execute ("CREATE TABLE tblNJDOC(ProductName VARCHAR(125), " & _
-
"NDC_1 VARCHAR(75), " & _
-
"GPI varchar(20), " & _
-
"QuantitySummed currency, " & _
-
"AmountBilledSummed currency, " & _
-
"BillFeeSummed currency, " & _
-
"CostBilledSummed currency)")
-
-
'Bind rstTemp to the temporary table
-
Set rstTemp = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset)
-
Set rstSummary = CurrentDb.OpenRecordset("tblNJDOC")
-
-
-
'*********temp fields for writing records
-
Dim strProductName_TEMP As String
-
Dim strNDC_1_TEMP As String
-
Dim strGPI_TEMP As String
-
Dim strQuantitySummed_TEMP As Integer
-
Dim strAmountBilledSummed_TEMP As Integer
-
Dim strBillFeeSummed_TEMP As Integer
-
Dim strCostBilledSummed_TEMP As Integer
-
-
Dim strNDC_1_Stack As String
-
-
-
strFirstRec = "Yes"
-
strProductName_TEMP = " "
-
strNDC_1_TEMP = " "
-
strGPI_TEMP = " "
-
strQuantitySummed_TEMP = 0
-
strAmountBilledSummed_TEMP = 0
-
strBillFeeSummed_TEMP = 0
-
strCostBilledSummed_TEMP = 0
-
-
'Move the data into the temporary table
-
-
rstTemp.MoveFirst
-
-
Do While rstTemp.EOF = False
-
If strFirstRec = "Yes" Then
-
strFirstRec = "No"
-
strProductName_TEMP = rstTemp!ProductName
-
strNDC_1_TEMP = rstTemp!NDC_1
-
strGPI_TEMP = rstTemp!GPI
-
strQuantitySummed_TEMP = rstTemp!QuantitySummed
-
strAmountBilledSummed_TEMP = rstTemp!AmountBilledSummed
-
strBillFeeSummed_TEMP = rstTemp!BillFeeSummed
-
strCostBilledSummed_TEMP = rstTemp!CostBilledSummed
-
End If
-
-
If rstTemp!ProductName = strProductName_TEMP Then
-
If rstTemp!NDC_1 = strNDC_1_TEMP Then
-
strNDC_1_Stack = strNDC_1_TEMP
-
Else
-
strNDC_1_Stack = strNDC_1_Stack + "/ " + rstTemp!NDC_1
-
rstTemp!NDC_1 = strNDC_1_TEMP
-
End If
-
Else
-
' Write temp records to table
-
rstTemp.AddNew
-
rstSummary!ProductName = strProductName_TEMP
-
rstSummary!NDC_1 = strNDC_1_Stack
-
rstSummary!GPI = strGPI_TEMP
-
rstSummary!QuantitySummed = strQuantitySummed_TEMP
-
rstSummary!AmountBilledSummed = strAmountBilledSummed_TEMP
-
rstSummary!BillFeeSummed = strBillFeeSummed_TEMP
-
rstSummary!CostBilledSummed = strCostBilledSummed_TEMP
-
rstTemp.Update
-
-
' Move rst (record set) into the temp fields
-
-
strProductName_TEMP = rstTemp!ProductName
-
strNDC_1_TEMP = rstTemp!NDC_1
-
strGPI_TEMP = rstTemp!GPI
-
strQuantitySummed_TEMP = rstTemp!QuantitySummed
-
strAmountBilledSummed_TEMP = rstTemp!AmountBilledSummed
-
strBillFeeSummed_TEMP = rstTemp!BillFeeSummed
-
strCostBilledSummed_TEMP = rstTemp!CostBilledSummed
-
' move to next record set (rst)
-
End If
-
-
rstTemp.MoveNext
-
Loop
-
-
' write last record
-
rstSummary.AddNew
-
rstSummary!ProductName = strProductName_TEMP
-
rstSummary!NDC_1 = strNDC_1_Stack
-
rstSummary!GPI = strGPI_TEMP
-
rstSummary!QuantitySummed = strQuantitySummed_TEMP
-
rstSummary!AmountBilledSummed = strAmountBilledSummed_TEMP
-
rstSummary!BillFeeSummed = strBillFeeSummed_TEMP
-
rstSummary!CostBilledSummed = strCostBilledSummed_TEMP
-
rstSummary.Update
-
-
rstTemp.Close
-
rstSummary.Close
-
-
-
Create_tblNJDOC_Exit:
-
Exit Sub
-
-
-
Err_Hndlr:
-
MsgBox "[" & Err.Number & "]: " & Err.Description, vbInformation, "Create_tblNJDOC()"
-
-
5 2407
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)
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.
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. - CurrentDb.Execute ("CREATE TABLE tblNJDOC(ProductName VARCHAR(125), " & _
-
"NDC_1 VARCHAR(75), " & _
-
"GPI varchar(20), " & _
-
"QuantitySummed currency, " & _
-
"AmountBilledSummed currency, " & _
-
"BillFeeSummed currency, " & _
-
"CostBilledSummed currency)")
-
-
DoEvents
-
-
'Bind rstTemp to the temporary table
-
Set rstTemp = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset)
-
Set rstSummary = CurrentDb.OpenRecordset("tblNJDOC")
This will insure that tblNJDOC is created before you try to use it.
Mary
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.
so by not setting dbs = currentDB, vba will assume it is the current database in use?
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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 =...
|
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()...
|
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...
|
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
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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,...
| | |