zelarra821
Registered User.
- Local time
- Today, 20:46
- Joined
- Jan 14, 2019
- Messages
- 834
Hi. I'm trying to improve the behavior of an inputbox, but I can not. This is the code that I have developed (although I have it in Spanish, I have translated it into English):
And the problems I have are:
1. In the first inputbox (signo), I want to achieve that if the user enters a value that is not a comparison operator (>, <,> =, <=), an error will be thrown telling him that he must write a valid character.
2. In the second inputbox (valor), I want to get that if user writes any value that is not a number, I will error.
I think that would solve that, but I would have to try it once these two points work well.
Thanks.
Code:
On Error Resume Next
Dim miFiltro As String
Dim Valor As String
Dim Signo As String
'If the value of the field is numeric, we can continue
If IsNumeric(Screen.PreviousControl) Then
'We leave the event if the name of the field matches any of the following
If Screen.PreviousControl.Name = "Autor" Then
MsgBox "El campo que has seleccionado no está disponible para este filtro.", vbInformation
Exit Sub
End If
If Screen.PreviousControl.Name = "Subgenero" Then
MsgBox "El campo que has seleccionado no está disponible para este filtro.", vbInformation
Exit Sub
End If
If Screen.PreviousControl.Name = "Formato" Then
MsgBox "El campo que has seleccionado no está disponible para este filtro.", vbInformation
Exit Sub
End If
If Screen.PreviousControl.Name = "Goodreads" Then
MsgBox "El campo que has seleccionado no está disponible para este filtro.", vbInformation
Exit Sub
End If
If Screen.PreviousControl.Name = "EsSerie" Then
MsgBox "El campo que has seleccionado no está disponible para este filtro.", vbInformation
Exit Sub
End If
If Screen.PreviousControl.Name = "Serie" Then
MsgBox "El campo que has seleccionado no está disponible para este filtro.", vbInformation
Exit Sub
End If
If Screen.PreviousControl.Name = "Biblioteca" Then
MsgBox "El campo que has seleccionado no está disponible para este filtro.", vbInformation
Exit Sub
End If
'We introduce our first InputBox
Signo = InputBox("Introduce el signo: mayor (>), menor (<), mayor que (>=) o menor que (<=).", "Filtrar por rango")
'If the user cancels the InputBox, we exit
If StrPtr(Signo) = 0 Then Exit Sub
'If the user leaves the Input blank, a message appears indicating the error and we exit
If Signo = "" Then
MsgBox "Debes introducir un carácter válido.", vbInformation
Exit Sub
End If
'If the user enters a character that does not correspond to a comparison operator, a message appears with the error and we exit
If Signo <> ">" Or Signo <> "<" Or Signo <> ">=" Or Signo <> "<=" Then
MsgBox "Has introducido un carácter erróneo.", vbInformation
Exit Sub
End If
'We introduce our second InputBox
Valor = InputBox("Introduce el valor")
'If the user cancels the InputBox, we exit
If StrPtr(Valor) = 0 Then Exit Sub
'If the user leaves the Input blank, a message appears indicating the error and we exit
If Valor = "" Then
MsgBox "Debes introducir un carácter válido.", vbInformation
Exit Sub
End If
'If the user enters a non-numeric character, a message appears with the error and we exit
If IsNumeric(Valor) = False Then
MsgBox "Has introducido un carácter erróneo.", vbInformation
Exit Sub
End If
'Let's take the selected value and the field and create the approximate filter
miFiltro = Screen.PreviousControl.Name & Signo & Replace(Valor, ",", ".")
'We apply the filter to the form
Me.Filter = miFiltro
Me.FilterOn = True
And the problems I have are:
1. In the first inputbox (signo), I want to achieve that if the user enters a value that is not a comparison operator (>, <,> =, <=), an error will be thrown telling him that he must write a valid character.
2. In the second inputbox (valor), I want to get that if user writes any value that is not a number, I will error.
I think that would solve that, but I would have to try it once these two points work well.
Thanks.