Hi,
I'm a relatively new VBA programmer but have been given the task of
repairing a database that currently appears with "3146 ODBC--call
failed." This happens when various criteria are input into a form
(called InvCredit), and then cmdProcess is clicked. Then we are asked
if we can "Confirm you want to process?" and when Yes is clicked the
error appears. Following is the code. I have found that the break
appears at the .Update point close to the bottom.
Thanks,
J.Meager
Private Sub cmdProcess_Clic k()
On Error GoTo handler
If MsgBox("Confirm you want to process", 292) = vbNo Then Exit Sub
Dim db As DAO.Database
Dim rsReq As DAO.Recordset
Dim strSQL As String
Dim dteLoop As Date
Dim lngInvNo As Long
dteLoop = Format(DateFrom , "long date")
Set db = CurrentDb
strSQL = "SELECT DateRequired,Sc hoolCodeID,Requ ired,InvoiceNum ber,InvoiceDate ,ProductID,InvC red,Requirement sID
FROM tblRequirements ;"
Set rsReq = db.OpenRecordse t(strSQL, 2, dbSeeChanges, 2)
lngInvNo = DLookup("[Next Invoice Number]", "Control")
strSQL = "UPDATE Control SET [Next Invoice Number]=[Next Invoice
Number]+1;"
db.Execute strSQL
With rsReq
Do
.AddNew
!DateRequired = dteLoop
!SchoolCodeID = SchoolName
'!Required = AdjustmentQuan
!Required = Nz(Me(Format(dt eLoop, "dddd")), 0)
!InvoiceNumber = lngInvNo
!InvoiceDate = Date
!ProductID = Products.Column (3)
Debug.Print Format(dteLoop, "dddd")
!InvCred = IIf(Nz(Me(Forma t(dteLoop, "dddd")), 0) < 0, 1, 0)
.Update
dteLoop = dteLoop + 1
Loop Until dteLoop > Format(DateTo, "long date")
End With
DoCmd.OpenRepor t "InvoiceInvCred ", acViewPreview, , "InvoiceNumber= " &
lngInvNo
Exit Sub
handler:
Select Case Err.Number
Case 3022
Resume Next
Case Else
MsgBox Err.Number & " " & Err.Description
End Select
End Sub 1 4938
Doolittle wrote: Hi, I'm a relatively new VBA programmer but have been given the task of repairing a database that currently appears with "3146 ODBC--call failed." This happens when various criteria are input into a form (called InvCredit), and then cmdProcess is clicked. Then we are asked if we can "Confirm you want to process?" and when Yes is clicked the error appears. Following is the code. I have found that the break appears at the .Update point close to the bottom.
Thanks, J.Meager
Private Sub cmdProcess_Clic k() On Error GoTo handler If MsgBox("Confirm you want to process", 292) = vbNo Then Exit Sub Dim db As DAO.Database Dim rsReq As DAO.Recordset Dim strSQL As String Dim dteLoop As Date Dim lngInvNo As Long dteLoop = Format(DateFrom , "long date")
Set db = CurrentDb strSQL = "SELECT DateRequired,Sc hoolCodeID,Requ ired,InvoiceNum ber,InvoiceDate ,ProductID,InvC red,Requirement sID FROM tblRequirements ;"
Set rsReq = db.OpenRecordse t(strSQL, 2, dbSeeChanges, 2)
lngInvNo = DLookup("[Next Invoice Number]", "Control")
strSQL = "UPDATE Control SET [Next Invoice Number]=[Next Invoice Number]+1;" db.Execute strSQL
With rsReq
Do .AddNew !DateRequired = dteLoop !SchoolCodeID = SchoolName '!Required = AdjustmentQuan !Required = Nz(Me(Format(dt eLoop, "dddd")), 0) !InvoiceNumber = lngInvNo !InvoiceDate = Date !ProductID = Products.Column (3) Debug.Print Format(dteLoop, "dddd") !InvCred = IIf(Nz(Me(Forma t(dteLoop, "dddd")), 0) < 0, 1, 0) .Update dteLoop = dteLoop + 1 Loop Until dteLoop > Format(DateTo, "long date") End With
DoCmd.OpenRepor t "InvoiceInvCred ", acViewPreview, , "InvoiceNumber= " & lngInvNo Exit Sub handler: Select Case Err.Number Case 3022 Resume Next Case Else MsgBox Err.Number & " " & Err.Description End Select End Sub
One suggestion. You use MsgBox("Confirm you want to process", 292) and
Set rsReq = db.OpenRecordse t(strSQL, 2, dbSeeChanges, 2). Unless you
have memorized all the possible constants and don't mind adding them up,
why not spell your stuff out? Why not use VbYesNo + vbQuestion + ...?
It's much easier for those reading your code to make a comment.
I would next put a comment (') in front of your OnError Goto line.
You say it breaks on the .Update line. I would then change your line
Set rsReq = db.OpenRecordse t(strSQL, 2, dbSeeChanges, 2)
to
Set rsReq = db.OpenRecordse t(strSQL, dbOpenDynaset)
Maybe play around with various settings. In fact, I'd make a copy of
your table, call it Test, and attempt to add a record to Test.
Also, do you have any validation rules or fields that are required but
you don't update or fill with data? Overall, your code looks fine, but
somethings not quite right if it errors on you.
Also, does it add any records in your loop? Or does it bomb on the
first pass? I would step thru your code by clicking on the vertical bar
in the code window next to the With rsReq. When you run the code you
can follow the steps line by line and see the values you are storing.
Hmmmm...actuall y I think the problem is with the line
!InvCred = IIf(Nz(Me(Forma t(dteLoop, "dddd")), 0) < 0, 1, 0)
What is Me(Format...?
"dddd" returns a day, as in Wednesday. How would that be less than
zero? How could Wednesday ever be less than zero?
Why not state !InvCred = IIF(IsNull(dteL oop), 1, 0)
That line is really goofy. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Tom Jones |
last post by:
I need to access databases on both win2k and Linux systems but I have to set
up the DSNs under program control ... no uses using GUIs ...
Has anyone done this? if so can we discuss it either in here or offline?
thanks
Tom
|
by: JMCN |
last post by:
hi -
i have created a passthrough query and have it automatically connect
to the odbc and then on a separate form, i have the user type in the
date parameters. however when i run the following code on my form, i
receive an error that the odbc connection had failed "ODBC – call
failed. (Error 3146)", even though in the pass-through query i pasted
the properties odbc connect str to the qdf.connect code below. does
anyone know why i have...
|
by: jj |
last post by:
This is strange, I've got an Access database developed that transfers
records to and from a remote database via Linked Tables/ODBC. It works fine
when connected to the development server. Same Access database pointed to
the production database server adn it returns this error after a short
period of time.
It's not like it dies right away, it'll transfer say 2000 of 4000 records,
try again and it'll transfer 1000 or 4000 records. So...
|
by: Jimbo |
last post by:
I have an access 97 database linked to sql server..I click update on a
form
and get an error message:
Run-time error 3146 ODBC call failed
The debugger points to this line:
MyTable.Update
|
by: Harmony407 |
last post by:
Hello:
Our organization uses MS Access to store all of our members
information.
Our primary database computer is running on Windows 98. This is where
the main database exists. The MS Access version we are running is MS
Access 95, V7. I know it is very old, but the organization is afraid
to update to a newer version for fear of losing data. So, I must work
with what I have.
| |
by: thetuckers_jersey |
last post by:
I have inherited an Access database with a SQL backend and need to run
a daily report. When I try to run this report which calls stored
procedures, I get the following VB error message : Run-time error 3146
ODBC call failed.
The debug screen is as below :
Private Sub Report_Open(Cancel As Integer)
countline = 0
Dim qdf As QueryDef
|
by: coolminded |
last post by:
Hi All
when i execute a function in vb , it shows the run time error,'odbc call failed', but when i tired the same function in the postgresql then it executes perfectly. why the function cannot run in the vb but in the postgresql when the database is huge. but the same function runs in the vb itself when the database is small.
any suggestion is appreciated..
thanx in advance.
|
by: Ramya Shree S |
last post by:
Hi all,
One of my application uses VB 3 and MS ACCESS as database. I am getting error 3146 ODBC connection failed when i try to retrieve the records.
Please consider this as high priority issue and help me in fixing the same.
Regards
Ramya
|
by: Amrut |
last post by:
Hi all,
I am a vba programmer. I am getting an error message as odbc call failed.
I am using a linked table having upto 72 laks records.
Pl help me. its very urgent.
strsql = "Select * from Where site='0801' and item_code='TJC500411' and bal_qty > 0 and tran_type = 'RCT-TR' and tran_date in (Select distinct tran_date from Where tran_date between #30/05/2005# and #30/05/2007# and site <> '0801' and item_code='TJC500411' and bal_qty >...
|
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...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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...
|
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...
|
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...
|
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...
|
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();...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |