Replace Case txt_name = "but_next"
with Case "but_next"
. Correct code is:
Private Sub zmien_fakture(ByVal txt_name As String)
Select Case txt_name
Case "but_next"
If Lastrow > nr_faktury_dol Then
nr_faktury_dol = nr_faktury_dol + 1
Else
MsgBox ("To jest ostatnia faktura")
End If
Case "but_prev"
If nr_faktury_dol <> 1 Then: nr_faktury_dol = nr_faktury_dol - 1
Case Else
End Select
End Sub
Why your syntax is not working:
When you're using Case txt_name = "but_next"
, statement txt_name = "but_next"
evaluates to TRUE
or FALSE
and you get:
Select Case txt_name ' txt_name="but_next", but txt_name<>TRUE and txt_name<>FALSE
Case True
'do something
Case False
'do something
Case Else
End Select
But in Select Case txt_name
variable txt_name
is NOT True
or False
and you actually jumps to Case Else
part.
Alternative approach is to change Select Case txt_name
to Select Case TRUE
like this:
Private Sub zmien_fakture(ByVal txt_name As String)
Select Case True
Case txt_name = "but_next"
If Lastrow > nr_faktury_dol Then
nr_faktury_dol = nr_faktury_dol + 1
Else
MsgBox ("To jest ostatnia faktura")
End If
Case txt_name = "but_prev"
If nr_faktury_dol <> 1 Then: nr_faktury_dol = nr_faktury_dol - 1
Case Else
End Select
End Sub