Solved

Getting error on CurrentDb.Execute ("UPDATE statement

Posted on 2016-11-09
15
42 Views
Last Modified: 2016-11-17
I'm trying to use CurrentDB.Execute for an "UPDATE statement.  I'm tripping on the dbFailOnError.  How do I find out what error I'm getting?

Judith
0
Comment
Question by:JudithARyan
  • 7
  • 5
  • 2
  • +1
15 Comments
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 41881041
you need to include an error handler routine and tell Access to use that error handler if an error is encountered.  Generally a procedure might look something like:
Private Sub cmd_Update_Click()

    On Error goto ProcError

    strSQL = "UPDATE yourTable SET [SomeNumberField] = " & me.txtNewValue _
           & " WHERE [SomeOtherField] = " & me.OtherValue
    currentdb.execute strsql, dbfailonerror

ProcExit:
    Exit Sub

ProcError:
    msgbox err.number & vbcrlf & err.description, , "cmd_Update_Click"
    debug.print "cmd_Update_Click", err.number, err.description

End Sub

Open in new window

0
 

Author Comment

by:JudithARyan
ID: 41881056
If I'm using ProcError, why do I need dbFailOnError ?

Judith
0
 
LVL 47

Assisted Solution

by:Dale Fye (Access MVP)
Dale Fye (Access MVP) earned 125 total points
ID: 41881071
because without dbFailOnError, the Execute command will not raise an error if an error is encountered.  You must use the dbFailOnError if you want to be able to figure out what the error was, and present a meaningful message to the user.  The example I gave you is the simplest form of error handler.  I normally have a series of If statements in mine, something like:
    'Other code here
    '...

ProcError:
    'the following error numbers are made up
    If err.Number = 1234 Then
        msgbox "you failed to enter ... please try again"
        resume procExit
    elseif err.number = 321 then
        msgbox "Some other meaningful message"
        Resume Next  'you might want to simply continue processing after some errors
    elseif err.number = 987 Then
        'you might want to set some value and try the statement that originally raised the error
        me.txt_SomeValue = 0
        Resume
    Else
        msgbox err.number & vbcrlf & err.description, , "cmd_Update_Click"
        debug.print "cmd_Update_Click", err.number, err.description
        Resume ProcExit
    End If

End Sub

Open in new window

0
 
LVL 75
ID: 41881251
Can you post the SQL of the Update statement or a screen shot from the query grid ?
0
 

Author Comment

by:JudithARyan
ID: 41888307
Sorry I haven't responded, I got distracted by other work.  

I did try your code, Dale, and got an error #0.  When I tried to figure out the problem, my changes led to a problem with my combo box that I'm have to dig out of.  Let me work on this and I'll send you a sample of the code and data.

Judith
0
 

Author Comment

by:JudithARyan
ID: 41888354
I've gotten myself in a real mess.  The form I'm working on is called by an autoexec module.  So when it gets an error it hangs and I can't get back into the program to do anything.

Is there a Function Key that will help me break into this problem?

Judith
0
 
LVL 57

Assisted Solution

by:Jim Dettman (Microsoft MVP/ EE MVE)
Jim Dettman (Microsoft MVP/ EE MVE) earned 125 total points
ID: 41888382
Hold down the shift key when you open the DB and the autoexec won't fire.

Jim.
0
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 

Author Comment

by:JudithARyan
ID: 41888518
I'm attaching a file with images about my form.  Hopefully you can read it.  It's in PDF.

JudithLogonFormInfo.pdf
0
 
LVL 75
ID: 41888573
OK ... I'm confused now as to what the actual problem is at this point?
With CurrentDB.Execute ?
Or there is a problem with a Form ?
0
 

Author Comment

by:JudithARyan
ID: 41888582
After getting the response from Dale, I've come to realize that it is probable a form problem with the only combo box on it.  Sorry for the confusion!

Should I close this question and open a different one?

Judith
0
 
LVL 75
ID: 41888595
Well ... what is the specific problem now?
Also ... in the last screen shot - in the Row Source property ... there is some kind of character (') just before the word SELECT .... ???
0
 

Author Comment

by:JudithARyan
ID: 41888748
The SELECT statement is started & ended with "s.

When I open the form, I get the following error message:

The record source '~sq_cfrmSysLogon2013~sq_cContactID' specified on this form or report does not exist.

As you can see by my record source query results, it does!  

?????

Judith
0
 
LVL 75
ID: 41888825
I don't think you want "" surround the SQL stmt ...
And double check if that SQL will run alone in the query grid ?
0
 

Author Comment

by:JudithARyan
ID: 41890100
Here's the data table and the record source query results for the form.

Hope this helps.

JudithLogonFormData.pdf
0
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Access MVP) earned 250 total points
ID: 41890689
This
'~sq_cfrmSysLogon2013~sq_cContactID'

is usually the type of Name your would find in MSysObjects for an SQL Statement used as a Form/Report Record Source or the Row Source for a combo box.
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
FormulaArray VBA Issue 6 17
how to link subforms ms/access VBA 6 27
Importing and Dropping Table in Access 11 24
Export Query data to excel file 14 33
Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now