Updating recod (1 Viewer)

JBurlison

Registered User.
Local time
Today, 13:59
Joined
Mar 14, 2008
Messages
172
Quote:
Originally Posted by JBurlison
Here is an example of a password change VBA code in my eyes, i have not been doing this long so please correct me if im wrong.


Code:
Code:
Dim Currentpass As String 'This is the current password
Dim Newpass As String 'This is the new password

'At this point you should have 3 text boxes in your form 2 for new passwords (to confirm that they match and 1 to confirm the Old password. For this purpose we will name the text boxes Txt_old, Txt_newone, Txt_newtwo

CurrentPass = [Your Current password field here] 'Dlookup if necessary

If Currentpass = Txt_old Then

            Newpass = Txt_newone

                 If Newpass = Txt_newtwo
                            [Your Current password field here] = Newpass
                 Else
                   MsgBox "Your New Passwords Do Not Match"
                 End If
Else
MsgBox "Current password invalid, Please try again"
End If
Just my outtake on it as to what i have learned from VBA this past month. this could be wrong tho. like i said i am still new to VBA

This will work but you will need to add code to store Newpass in your password table. This will entail opening a recordset and finding the relevant user record and then updating the password field. Finally closing the record.

How Can i do This? can someone post some sample code?

This will work but you will need to add code to store Newpass in your password table. This will entail opening a recordset and finding the relevant user record and then updating the password field. Finally closing the record
 

modest

Registered User.
Local time
Today, 13:59
Joined
Jan 4, 2005
Messages
1,220
This has to do with attaching a form to a table that has a password field.

The form has 3 textboxes; one for the original password, and two for the new password (one is used as verification of correct input).

The problem with doing what is shown here is that there is no username associated with the password, so if this list has multiple accounts and two people have the same password, you would be changing everyone that has the same password.

Instead of asking how to do this, I think a better thing for you to post is an explanation of what you have and what you're trying to do.
 

JBurlison

Registered User.
Local time
Today, 13:59
Joined
Mar 14, 2008
Messages
172
Ugh, thats not the issue, that just sample code. i just want to know how to open a recordset and update it with a value. I.E. im changing the password on a form how do i update that pasword on the Table.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 18:59
Joined
Sep 12, 2006
Messages
15,651
look at recordsets


effectively, investigate these

openrecordset (rst.openrecordset)
movetocorrectitem (rst.find) or (rst.seek)
start an edit (rst.edit)
edit the password (rst!password = whatever - note the different syntax)
saveit (rst.update)
close the recordset (rst.close)

hope this helps
 

JBurlison

Registered User.
Local time
Today, 13:59
Joined
Mar 14, 2008
Messages
172
Thank You! exacty what i am looking for perfect!
 

modest

Registered User.
Local time
Today, 13:59
Joined
Jan 4, 2005
Messages
1,220
Well the issue is are you trying to update through an objects event, or strictly through code. If you have a form attached to a table, you don't need to be messing with VBA, however if you want to strictly do it through VBA then I would look into DAO recordsets.

Ex.
Code:
Dim db as DAO.Database
Dim rs as DAO.Recordset

Set db = CurrentDb
Set rs = db.OpenRecordset("table name", dbOpenDynaset)

With rs
   .findfirst 'Whatever meets your primary key condition here to find the record you want to update
   .edit
      .fields("password field") = "value"
   .update
End With

Note you will need to make a reference to your DAO library
 
Last edited:

JBurlison

Registered User.
Local time
Today, 13:59
Joined
Mar 14, 2008
Messages
172
would i have to do DAO if it is in the same access database?
Some sample code to see if im understanding this correctly

Code:
Dim db as DAO.Database
Dim rs as DAO.Recordset


Set db = "Sai Inventory"
Set rs = db.OpenRecordset("Main Inventory", dbOpenDynaset)

With rs
   .findfirst Me.Sai_Serial_Number_.Value = [Sai Serial Number]
   .edit
   .fields("Location") = "SAI, Shelton"
   .update
End With
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 18:59
Joined
Sep 12, 2006
Messages
15,651
try this

Code:
Dim db as DAO.Database
Dim rs as DAO.Recordset

Set db = currentdb 'set ref to currentdb - the one you are in
Set rs = db.OpenRecordset("Main Inventory", dbOpenDynaset)

With rs
'the first bit should be a field in the table
'the second bit should be a reference on the form (or a variable)
'note the & syntax to link the bits together
   .findfirst "[Sai_Serial_Number] =  "
 
Last edited:

JBurlison

Registered User.
Local time
Today, 13:59
Joined
Mar 14, 2008
Messages
172
Ok here we go lets try this,

Code:
Private Sub Command73_Click()

Dim db As DAO.Database
Dim rs As DAO.Recordset

Set db = CurrentDb
Set rs = db.OpenRecordset("Main Inventory", dbOpenDynaset)


If Me.Sai_Serial_Number_1r.Value = "" Or IsNull(Me.Sai_Serial_Number_1r.Value) Then
      
      Else

With rs
   .FindFirst "[Sai Serial Number] = '" & Me.Sai_Serial_Number_1r.Value & "'"
   .Edit
   .Fields("Location") = "SAI, Shelton"
   .Update
End With
   
End If
   
   
End Sub
 

Users who are viewing this thread

Top Bottom