Help with indent vba code :) (1 Viewer)

FreshCoder

Registered User.
Local time
Yesterday, 20:39
Joined
Sep 22, 2018
Messages
33
Hi again:)

Ive been strugling to make this through but i miss out the indents....
Can someone plz help me out correcting ?
Thanks


Code:
Option Compare Database
Option Explicit
Private lengde As Integer


Private Sub comBeregn_Click()
    Dim strsql As String
    Dim stdset As DAO.Recordset
    Dim max As Integer
    Dim min As Integer
    Dim rest As Integer

    strsql = "DELETE * FROM ListerOK"
    CurrentDb.Execute (strsql)


    strsql = "INSERT INTO ListerOK (lengde2) SELECT lengde FROM Lister WHERE lengde <= 200"
    CurrentDb.Execute (strsql)

If txtMax <> "" Then
    max = txtMax
Else
    max = 200
End If

If txtMin <> "" Then
    min = txtMin
Else
    min = 30
End If

strsql = "SELECT * FROM Lister"
Set stdset = CurrentDb.OpenRecordset(strsql)
With stdset
    Do While Not .EOF
If !lengde >= min And !lengde <= max Then
        strsql = "INSERT INTO ListerOK (lengde2) VALUES (" & lengde & ")"
        CurrentDb.Execute (strsql)
ElseIf !lengde > max + min Then
    rest = !lengde - max
    strsql = "INSERT INTO ListerOK (lengde2) VALUES (" & max & ")"
    CurrentDb.Execute (strsql)
    Do While rest <> 0
If rest > max + min Then
    rest = rest - max
    strsql = "INSERT INTO ListerOK (lengde2) VALUES (" & max & ")"
    CurrentDb.Execute (strsql)
ElseIf rest >= min And rest <= max Then
    strsql = "INSERT INTO ListerOK (lengde2) VALUES (" & rest & ")"
    CurrentDb.Execute (strsql)
    rest = 0
ElseIf rest < max + min And rest > max Then
    rest = rest - min
    strsql = "INSERT INTO ListerOK (lengde2) VALUES (" & min + rest & ")"
    CurrentDb.Execute (strsql)
    rest = 0
End If
Loop

ElseIf !lengde < max + min And !lengde > max Then
    rest = !lengde - min
    strsql = "INSERT INTO ListerOK (lengde2) VALUES (" & min & ")"
    CurrentDb.Execute (strsql)
    strsql = "INSERT INTO ListerOK (lengde2) VALUES (" & rest & ")"
    CurrentDb.Execute (strsql)
    rest = 0
ElseIf !lengde < min Then
End If
    .MoveNext
    Loop
.Close
End With

DoCmd.OpenTable "ListerOK", acViewNormal

End Sub
 

Attachments

  • Grandfinalesoon.accdb
    648 KB · Views: 65

Minty

AWF VIP
Local time
Today, 04:39
Joined
Jul 26, 2013
Messages
10,380
Does this help;
Code:
Private Sub comBeregn_Click()
    Dim strsql As String
    Dim stdset As DAO.Recordset
    Dim max As Integer
    Dim min As Integer
    Dim rest As Integer

    strsql = "DELETE * FROM ListerOK"
    CurrentDb.Execute (strsql)


    strsql = "INSERT INTO ListerOK (lengde2) SELECT lengde FROM Lister WHERE lengde <= 200"
    CurrentDb.Execute (strsql)

    If txtMax <> "" Then
        max = txtMax
    Else
        max = 200
    End If

    If txtMin <> "" Then
        min = txtMin
    Else
        min = 30
    End If

    strsql = "SELECT * FROM Lister"
    Set stdset = CurrentDb.OpenRecordset(strsql)
    With stdset
        Do While Not .EOF
            If !lengde >= min And !lengde <= max Then
                strsql = "INSERT INTO ListerOK (lengde2) VALUES (" & lengde & ")"
                CurrentDb.Execute (strsql)
            ElseIf !lengde > max + min Then
                rest = !lengde - max
                strsql = "INSERT INTO ListerOK (lengde2) VALUES (" & max & ")"
                CurrentDb.Execute (strsql)
                Do While rest <> 0
                    If rest > max + min Then
                        rest = rest - max
                        strsql = "INSERT INTO ListerOK (lengde2) VALUES (" & max & ")"
                        CurrentDb.Execute (strsql)
                    ElseIf rest >= min And rest <= max Then
                        strsql = "INSERT INTO ListerOK (lengde2) VALUES (" & rest & ")"
                        CurrentDb.Execute (strsql)
                        rest = 0
                    ElseIf rest < max + min And rest > max Then
                        rest = rest - min
                        strsql = "INSERT INTO ListerOK (lengde2) VALUES (" & min + rest & ")"
                        CurrentDb.Execute (strsql)
                        rest = 0
                    End If
                Loop

            ElseIf !lengde < max + min And !lengde > max Then
                rest = !lengde - min
                strsql = "INSERT INTO ListerOK (lengde2) VALUES (" & min & ")"
                CurrentDb.Execute (strsql)
                strsql = "INSERT INTO ListerOK (lengde2) VALUES (" & rest & ")"
                CurrentDb.Execute (strsql)
                rest = 0
            ElseIf !lengde < min Then
            End If
            .MoveNext
        Loop
        .Close
    End With

    DoCmd.OpenTable "ListerOK", acViewNormal

End Sub
 

FreshCoder

Registered User.
Local time
Yesterday, 20:39
Joined
Sep 22, 2018
Messages
33
Thank you very much :)
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 20:39
Joined
Aug 30, 2003
Messages
36,139
I use a free add-in called Smart Indenter; indenting is then just a right-click away.
 

Users who are viewing this thread

Top Bottom