VBA question

G

Guest

Hi,

I am a VB developer and have been given a task to write some VBA code. I
know how to do these two through a recordset in VB but am not sure where to
go using VBA.

1.
What I want to do is open a table and return a password for the user that
has been input on a form. I have a table with all user names and passwords in
it and so I want to query the table and return the password so I can check it
against the password the user has entered.

2.
I would like to read through records in a table and write to a text file. I
need to read through each row so I can modify, calculate and check some
records.

Any help to perform either one of these tasks would be helpful. I have
looked at the OpenTable command but could not see how to move through the
records.

Thanks.

Stephen
 
A

Arvin Meyer [MVP]

There is virtually no difference between VB and VBA. Using Access, you have
the added advantage of opening a recordset against a saved query or a table.
You can also use a Select statement, like you most likely already do. If you
are using DAO, make sure you disambiguate the recordset like:

Dim rst As DAO.Recordset
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads
http://www.datastrat.com
http://www.mvps.org/access
 
K

Keith Wilby

Stephen M said:
1.
What I want to do is open a table and return a password for the user that
has been input on a form. I have a table with all user names and passwords
in
it and so I want to query the table and return the password so I can check
it
against the password the user has entered.

Have you considered implementing user-level security? You'd get all of that
functionality for free.

Regards,
Keith.
www.keithwilby.com
 
A

Albert D. Kallal

1.
What I want to do is open a table and return a password for the user that
has been input on a form. I have a table with all user names and passwords
in
it and so I want to query the table and return the password so I can check
it
against the password the user has entered.

You can use dlookup.

dim strPassword as string
dim strName as string

strName = "Albert"

strPassword = dlookup("PassWord","tblPasswords","UserName = '" & strName &
"'")

The above syntax for dlookup is

dlookup("field name to get","name of table","conditions")

The above example thus assumes a table called tblPassWords, a field name
with the password called Password, and a field name with users names called
UserName
I would like to read through records in a table and write to a text file.
I
need to read through each row so I can modify, calculate and check some
records.

You would find it easier to send the data to another table..and simply use
the export commands built into ms-access....less work then the your
approach. Furhter, depending on what you need to do, likey a sql query would
be even less work then sending the data to another table. Simply build the
query...and then export on that. (note that you can use VBA code and
functions as expressions in the sql...so, this is a powerfull concpet).

However, if you must write code...then here is the basic code shell...

dim rstRecords as dao.recordset
dim intF as interger
dim strF as string


strF = "c:\data\output.txt"
intF = freefile()

open strF for output as #intF

set rstReocrds = currentdb.openrecordset("tblcustomers")

do while rstReocrds.EOF = false
strOneline = rstRecords!LastName
strOneLine = strOneLine & " " rstReocrds!FirstName
print #intF, strOneLine
rstRecords.MoveNext
loop
rstRecords.Close

the above would create a text file and write out the firstname + lastname
field to the text file...

As I mentioned, you can use the built in commands, and depending on the
format of the output text file, it might mean you don't need to write any
code....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top