Solved

Endif and endwith problem

Posted on 2015-02-23
3
84 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Correct ordering 16 44
Combobox issue 4 25
Error compiling fairly simple database 3 16
Query output to Excel producing error 7 37
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

757 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

19 Experts available now in Live!

Get 1:1 Help Now