Login | |
|
 |
Access VB Script Question - 12/4/2005 5:33:22 AM
|
|
 |
|
| |
larry369
Posts: 1
Score: 0
Joined: 12/4/2005
Status: offline
|
Hi All, I just joined your Forum as I need help with VB Script for Access. I'm trying to synchronize a field in two tables and everything that i have tried from examples I have found on the web do not work. here are the details of my problem: I have a web site with a database. The database contains a table of user info with a field containing a user's password. Members can update their passwords. I have the master database on my hard drive. I need to keep the password field in this table in sync with the one on the web site. I have a query on the web site which extracts the passwords and creates a new table of users and their passwords in my database on my hard drive. What I want to do is parse thru the master table comparing the password field with the password field i downloaded from the web site and if the passwords are different to change my master table. This is the code that I was working with: ' Define Variables Dim dbMyDB As Database Dim rs1 As Recordset Set rs1 = dbMyDB.OpenRecordSet("tblMembers", dbOpenDynaset) Dim rs2 As Recordset Set rs2 = dbMyDB.OpenRecordSet("tblPasswords", dbOpenDynaset) 'Get number of records in tblMembers Records = rs1.recordcount 'Go to first record in tables DoCmd.GoToRecord acDataTable, "tblMembers", acFirst DoCmd.GoToRecord acDataTable, "tblPasswords", acFirst 'Update passwords Update_Passwords: If tblMembers.username = tblPasswords.username Then If tblMembers.password <> tblPasswords.password Then tblMembers.password = tblPasswords.password End If End If DoCmd.GoToRecord , , acNext Records = Records - 1 If Records > 1 Then GoTo Update_Passwords Exit Sub Access gives me an error on the first line. Can anyone help me solve this? Thanks. Larry
|
|
| |
|
|
|
 |
RE: Access VB Script Question - 12/5/2005 2:21:45 AM
|
|
 |
|
| |
csamuels
Posts: 42
Score: 0
Joined: 9/26/2005
Status: offline
|
here's two generic functions to open a connection & recordset to access (openconn) and close both the recordset & connection (closeconn). You'll need to dim the variables and change routefile to point to your db routefile = "c:\tasks\actagt2.mdb" sub openconn ' open a connection to access db' dim tries set conn = CreateObject("ADODB.Connection") 'prep connection' set rs = CreateObject("ADODB.Recordset") ' prep recordset' tries = 0 ' clear tries counter' do 'try to open connection to the db conn.open "DRIVER={Microsoft Access Driver (*.mdb)};" &_ "DBQ=" & RouteFile & ";DefaultDir=;UID=;PWD=;" tries = tries + 1 if (err.number <> 0) then 'if errored, close this connection conn.close end if Loop While (Err.Number<>0) And tries < 10 'if errored, try again. MAX TRIES = 10 end sub sub closeconn ' close the connection to the db rs.close set rs = nothing conn.close set conn = nothing end sub
|
|
| |
|
|
|
| |
|
|
 |
|
 |
|
|