i have a form login... that is connected to a ms access database... tables...
the form login will determine if you are already registered to the ms access database...
and it has a option to log in as administrator...
in administrator window you can edit username and password of all the currently registered user to it....
my problem is....
if you will edit username and password it will check if the username that you will change is already registered or not.... if it exist then it will exit if not it will continue to change your username/password...
the problem is the said code for check if exist username is correctly going for the first time you run the form after that without exiting the program
and try to change it again... to other username and password it will not detect if the username is already exist in the record tables
a clear example is this....
i have a field username and password like this in my current tables
test 1234 << the first word is my uername and the 2nd is the password...
test2 1234
test3 1234
i will login test 1234 then i will be transferred to my other form edit username password....
i will choose test 1234 to be changed
i will changed it to test2 1234
the result is username already exist so i will changed it to other username like this
test5 1234 click ok then after that username password successfully changed...
i will open my database record Accounts and i will see the username and password was updated right.... i will not close my edit username password windows... i will close my ms access database
now i will choose test2 1234 to be edit
i will changed it to test5 1234 same as the updated before....
then after clicking ok no username already exists have prompted me...
it says username password successfully changed.... why is it happening...
but when i try to look at the tables of my ms access it has been updated to test5 1234 same as the other...
i want my form to be updated even if i did'nt close it and open it again
please help me with this problem
this is some of my code
thanks in advanced for answering
the form login will determine if you are already registered to the ms access database...
and it has a option to log in as administrator...
in administrator window you can edit username and password of all the currently registered user to it....
my problem is....
if you will edit username and password it will check if the username that you will change is already registered or not.... if it exist then it will exit if not it will continue to change your username/password...
the problem is the said code for check if exist username is correctly going for the first time you run the form after that without exiting the program
and try to change it again... to other username and password it will not detect if the username is already exist in the record tables
a clear example is this....
i have a field username and password like this in my current tables
test 1234 << the first word is my uername and the 2nd is the password...
test2 1234
test3 1234
i will login test 1234 then i will be transferred to my other form edit username password....
i will choose test 1234 to be changed
i will changed it to test2 1234
the result is username already exist so i will changed it to other username like this
test5 1234 click ok then after that username password successfully changed...
i will open my database record Accounts and i will see the username and password was updated right.... i will not close my edit username password windows... i will close my ms access database
now i will choose test2 1234 to be edit
i will changed it to test5 1234 same as the updated before....
then after clicking ok no username already exists have prompted me...
it says username password successfully changed.... why is it happening...
but when i try to look at the tables of my ms access it has been updated to test5 1234 same as the other...
i want my form to be updated even if i did'nt close it and open it again
please help me with this problem
this is some of my code
Private Sub btnadmin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnadmin.Click
Dim logcheck As Boolean
Dim i As Integer
con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\Accounts.mdb"
con.Open()
sql = "Select * from tbluserAccount"
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(ds, "Accounts")
con.Close()
maxrows = ds.Tables("Accounts").Rows.Count
For i = 0 To maxrows - 1
If txtUsername.Text = ds.Tables("Accounts").Rows(i).Item("Username") And txtPassword.Text = ds.Tables("Accounts").Rows(i).Item("Password") And ds.Tables("Accounts").Rows(i).Item("Admin") = True Then
logcheck = True
i = maxrows - 1
Else
logcheck = False
End If
Next i
If logcheck = True Then
Me.Enabled = False
frmAdmin.Show()
Else
MsgBox("Invalid username/password")
End If
ds.Clear()
End Sub
Private Sub btnedit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnedit.Click
Dim index As Integer = ListBoxAccounts.SelectedIndex
Me.Enabled = False
frmEditUserPass.Show()
ds.Clear()
End Sub
Dim ds As New DataSet
Dim con As New OleDb.OleDbConnection
Dim sql As String
Dim maxrows As Integer
Dim index As Integer = frmAdmin.ListBoxAccounts.SelectedIndex
Dim da As New OleDb.OleDbDataAdapter
Private Sub btnOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOk.Click
Dim i As Integer
Dim newUser As String = txtEditUser.Text
Dim newPass As String = txtEditPass.Text
Dim retype As String = txtRetypePass.Text
connectToAccounts()
maxrows = ds.Tables("Accounts").Rows.Count
For i = 0 To maxrows - 1
If retype <> newPass Then
MsgBox("Password do not match")
i = maxrows - 1
ElseIf newPass.Contains(" ") Or retype.Contains(" ") Then
MsgBox("Spacing is not allowed in creating a new password")
i = maxrows - 1
ElseIf newUser.Equals(ds.Tables("Accounts").Rows(i).Item("Username")) Then
MsgBox("Username already exists")
i = maxrows - 1
Else
MsgBox("username/password changed successfully!")
Dim cb As New OleDb.OleDbCommandBuilder(da)
ds.Tables("Accounts").Rows(index).Delete()
Dim dsNewRow As DataRow
dsNewRow = ds.Tables("Accounts").NewRow
dsNewRow.Item("Username") = newUser
dsNewRow.Item("Password") = newPass
ds.Tables("Accounts").Rows.Add(dsNewRow)
cb.QuoteSuffix = "["
cb.QuoteSuffix = "]"
cb.QuotePrefix = "]"
cb.QuotePrefix = "["
da.Update(ds, "Accounts")
Dim table As DataTable = ds.Tables("Accounts").GetChanges(DataRowState.Modified)
i = maxrows - 1
Me.Close()
ds.Clear()
connectToAccounts()
End If
Next i
Public Sub connectToAccounts()
con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\Accounts.mdb"
con.Open()
sql = "SELECT * FROM tbluserAccount"
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(ds, "Accounts")
con.Close()
End Sub
thanks in advanced for answering