Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"Block If without End If" error message 1

Status
Not open for further replies.

NeilT123

Technical User
Jan 6, 2005
302
GB
Hi, I have been trying to create a dummy button in a continuous subform. I want to press the button and the FertRecStatus to change from yes to no and then back again. I need to requery the subform to change some formatting but I want the focus to stay with the line I originally clicked.

Below is my code which I have cobbled together and not yet tested but I am getting a "Block If without End If" error message and to be honest now can't see the wood from the trees.

Can anyone help point me in the right direction?

Code:
Private Sub CmdFertRecStatus_Click()
Dim lngKeyVal As Long
' This code saves the CroppingNumber value of the Subform
    lngKeyVal = Me.CroppingNumber
If Me.FertRecStatus = True Then
    Me.FertRecStatus = False
    Me.Requery
' This moves back to the original record
    With Me.RecordsetClone
    .FindFirst "[CroppingNumber] = " & lngKeyVal
    If Not .NoMatch Then
    Me.Bookmark = .Bookmark
    
ElseIf Me.FertRecStatus = False Then
    Me.FertRecStatus = True
    Me.Requery
    ' This moves back to the original record
    With Me.RecordsetClone
    .FindFirst "[CroppingNumber] = " & lngKeyVal
    If Not .NoMatch Then
    Me.Bookmark = .Bookmark
End If
End With
End Sub

Thanks as always
 
hi,

You cannot have blocks that are intertwined. Think of a block having all the code within it being indented...
Code:
Private Sub CmdFertRecStatus_Click()
    Dim lngKeyVal As Long
    ' This code saves the CroppingNumber value of the Subform
        lngKeyVal = Me.CroppingNumber

'[b]This has been moved OUT of the If..Then...ElseIf...End If block    
    With Me.RecordsetClone[/b]

        If Me.FertRecStatus = True Then
            Me.FertRecStatus = False
            Me.Requery
        ' This moves back to the original record
            .FindFirst "[CroppingNumber] = " & lngKeyVal
            If Not .NoMatch Then
            Me.Bookmark = .Bookmark
            
        ElseIf Me.FertRecStatus = False Then
            Me.FertRecStatus = True
            Me.Requery
            ' This moves back to the original record
            With Me.RecordsetClone
            .FindFirst "[CroppingNumber] = " & lngKeyVal
            If Not .NoMatch Then
            Me.Bookmark = .Bookmark
        End If
    End With
End Sub


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Furthermore:
...
If Not .NoMatch Then
Me.Bookmark = .Bookmark
[!]End If[/!]
...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thank you for the suggestions I managed to achieve what I wanted using the following code which uses refresh rather than requery and as a result the record pointer doesn't move

Code:
Private Sub CmdFertRecStatus_Click()
If Me.FertRecStatus = True Then
Me.FertRecStatus = False
If Me.Dirty Then Me.Dirty = False
Me.Refresh
ElseIf Me.FertRecStatus = False Then
Me.FertRecStatus = True
If Me.Dirty Then Me.Dirty = False
Me.Refresh
End If
End Sub
 
Again, lot of missing End If ...
Anyway, a simpler way:
Code:
Private Sub CmdFertRecStatus_Click()
Me.FertRecStatus = Not Me.FertRecStatus
If Me.Dirty Then Me.Dirty = False
Me.Refresh
End Sub

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PHV I like that. 20ish lines of code at the start down to 5. Thank you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top