Solved

Endif and endwith problem

Posted on 2015-02-23
3
88 Views
Last Modified: 2015-02-23
What it wrong with this code?  When I try to compile I get a End With without With error.

    If Me.txtCredit > 0 Then
        Me.txtCredit = Me.txtCurrentRecordAmount
        With RS
        .FindFirst "[ID]=" & Me.txtID
        If .NoMatch = True Then
            .AddNew
            !RecordDate = Me.txtRecordDate
            !Description = Me.txtDescription
            !Credit = Me.txtNewRecordAmount
        End With
        End If
    End If

Open in new window

0
Comment
Question by:SteveL13
3 Comments
 
LVL 22

Accepted Solution

by:
Kelvin Sparks earned 167 total points
ID: 40626200
Try this  

 If Me.txtCredit > 0 Then
        Me.txtCredit = Me.txtCurrentRecordAmount
        With RS
        .FindFirst "[ID]=" & Me.txtID
        If .NoMatch = True Then
            .AddNew
            !RecordDate = Me.txtRecordDate
            !Description = Me.txtDescription
            !Credit = Me.txtNewRecordAmount
        End If
        End With

    End If
0
 
LVL 47

Assisted Solution

by:Dale Fye (Access MVP)
Dale Fye (Access MVP) earned 167 total points
ID: 40626203
You also forgot to write the record.

!Credit = Me.txtNewRecordAmound
.Update  '<= need this too
0
 
LVL 84

Assisted Solution

by:Scott McDaniel (Microsoft Access MVP - EE MVE )
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 166 total points
ID: 40626553
Kelvin has you straight, but essentially you must "nest" your If - End If block INSIDE of your With - End With block. The way you had it first was:

Open With Block
Open If Block
Close With Block
Close If Block

Instead, you should have done (as Kelvin showed):

Open With Block
Open If Block
Close If Block
Close With Block
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
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…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

803 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