Avoid duplicating data when entering a new user

2

I have a database connection to access and visual% excel How can I make the code for the query that allows me to send a msgbox that tells me if the user is already registered?
I know that recordset is occupied

The code I have:

reuc.Open  "SELECT usuario" & "FROM Usuarios" & "WHERE usuario='" & TXT_USER.Text & "' " 

I want to know what value this one throws, if so it can be put in a if :

if reuc = TXT_USER.TEXT THEN  
    msgbox "Usuario existente"    
end if
    
asked by Costa Mendez Tapia 22.04.2016 в 00:29
source

1 answer

2

This should be your if

if reuc("usuario") = TXT_USER.TEXT THEN  
    msgbox "Usuario existente"    
end if

I recommend you check before your recordset is not empty.

If not reuc.EOF THEN

end If

If your query gets more than one user (it may sound weird, but it's for you to take it into account), you should go through the recordset integer and once the user has found the do until :

Dim encontrado As Boolean
Do until reuc .EOF and not encontrado
    if reuc("usuario") = TXT_USER.TEXT THEN  
        msgbox "Usuario existente"  
        encontrado = true
    end if

    reuc.MoveNext
Loop
    
answered by 22.04.2016 в 17:19