When one is out of practice easy becomes difficult. In this function I want to count the records with icliente status "pendiente" as criteria so we know if customer has a pending loan, but the function returns 0. What's wrong in the function?
Public Function prestamospendientes()
MsgBox(Me.txtid.Text)
Me.Refresh()
Dim prestamopendiente As Integer
Dim prestamostatus As String
Dim archivo As String
archivo = Application.StartupPath
Dim path As String
path = archivo & "\prestamos.accdb"
'clientes = path
Dim connection = " Provider=Microsoft.ace.OLEDB.12.0;" & _
"Data Source= " & path
Dim conn As New OleDbConnection(connection)
conn.Open()
Dim str = "select count(*) as prestamopendiente from [tblprestamosinteres] where [idcliente] = '" + txtid.Text + "'"
Dim cmd3 As OleDbCommand = New OleDbCommand(str, conn)
Dim dr As OleDbDataReader
dr = cmd3.ExecuteReader
MsgBox(prestamopendiente)
If dr.HasRows Then
dr.Read()
If IsDBNull(dr("prestamopendiente")) Then
prestamostatus = MessageBox.Show("Cliente tiene préstamo pendiente. " & vbCrLf _
& "No se puede realizar nuevo préstamo.", "Formulario Préstamo", MessageBoxButtons.OK, MessageBoxIcon.Warning)
gridclientes.Enabled = False
Else
prestamostatus = MessageBox.Show("Cliente no tiene préstamos pendientes. " & vbCrLf _
& "Favor proceder a realizar el préstamo.", "Formulario Préstamo", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
Else
prestamostatus = MessageBox.Show("Cliente xxxxno tiene préstamos pendientes. " & vbCrLf _
& "Favor proceder a realizar el préstamo.", "Formulario Préstamo", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
Return prestamostatus
dr.Close()
End Function