Search for registration using vba an Access form

0

again bothering, I'm learning a bit of vba, with macros in acces, what I try to do is that when entering the ID this make the corresponding query and show one of the fields in another text box, attached the image of the form and the code

However, when you click on search, the following is displayed.

and if I use a long id it throws the following error  error 6 occurred at run time: Overflow

this is the code I'm using

   Private Sub consultar_Click()

 Dim strSQL As String
 Dim ValCustID As Integer

 ValCustID = Me.idx.Value

 strSQL = "SELECT Modelo " & "FROM Motores " & "WHERE id='" & ValCustID & "';"

Modelox.Value = strSQL

End Sub
    
asked by JESUS ESPINOSA 17.12.2016 в 16:37
source

2 answers

1

Without having enough information from the table, it is likely that the id field is numeric. If the field is long, you should keep the data in the range between -2,147,483,648 and 2,147,483,647.

Seeing that the query is being searched as text, would also remove the quotes from the query:

strSQL = "SELECT Modelo FROM Motores WHERE id = " & ValCustID & ";"
    
answered by 04.01.2017 в 00:44
0

The error of overflow is because you are assigning a value to a variable outside its limits (integer is numeric by that means that you assign a value higher or lower than the one supported).

It is important to consult the documentation to determine the type of variable to be used in the project.

If you are only going to handle numbers, use the type Long or Double to extend the range.

Take into account if you are going to handle only integers, or figures with decimals.

    
answered by 09.02.2018 в 17:23