Solved

# Endif and endwith problem

Posted on 2015-02-23
88 Views
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
!RecordDate = Me.txtRecordDate
!Description = Me.txtDescription
!Credit = Me.txtNewRecordAmount
End With
End If
End If
0
Question by:SteveL13

LVL 22

Accepted Solution

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
!RecordDate = Me.txtRecordDate
!Description = Me.txtDescription
!Credit = Me.txtNewRecordAmount
End If
End With

End If
0

LVL 47

Assisted Solution

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

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

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…