Solved

Endif and endwith problem

Posted on 2015-02-23
3
86 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-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
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…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

863 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

21 Experts available now in Live!

Get 1:1 Help Now