Do not accept repeated records- VB6 validation

Asked By 0 points N/A Posted on -

I am working on my visual basic6.0 project.  What will be the code that I am going to use If I don't want any records to be repeated. For example, I add a user by clicking an add command button and I enter a user that is already existing in my access database. I want the program to don't accept my input and return an error message stating "Records already exist".

Can anyone give me a sample code in visual basic 6.0 on how to do this?


Answered By 0 points N/A #102087

Do not accept repeated records- VB6 validation


You may use the ADODB connection tool that is found in your references. Just add the Microsoft Active X 2.1 Library from Project–>References.

dim con as new adodb.connection
dim rs as new adodb.recordset
con.connectionstring(“ enter connection string”)
set rs=con.execute(“select distinct uname from accounts”)
if rs.fields(“uname”)=txtname then
 msgbox(“username already exist”)
 end sub
end if
connect to the database then enter the connection string, the accounts is the table name containing the usernames., then uname is the attribute name, rs contains the usernames currently in the database. the code checks all the usernames and reports “username already exists” if a match is found else the loop ends normally. The rest code may be appended at the end. Make sure that the database has atleast one record to execute it without a runtime error.
The program assumes that you have only a single username hat has to be matched, else you require a loop to search through if there is a match to the current username.

Related Questions