Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Endif and endwith problem

Posted on 2015-02-23
3
Medium Priority
?
107 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 668 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 49

Assisted Solution

by:Dale Fye
Dale Fye earned 668 total points
ID: 40626203
You also forgot to write the record.

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

Assisted Solution

by:Scott McDaniel (Microsoft Access MVP - EE MVE )
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 664 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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Suggested Courses

885 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