How can I tie a field from a form to runa macro?

  • Thread starter AccessNovice2005 via AccessMonster.com
  • Start date
A

AccessNovice2005 via AccessMonster.com

Need Help.

How do I tie a macro executed from a button on a form to the current record I
am looking at in that form?

I have a form that shows all the fields for a singe record from a sales table.

There are 3 comment fields which show the last 3 comments you had with a
client so you can keep a history. These fields are called "Comment1",
"Comment2" and "Comment3". (1 is the most recent comment, 3 is the oldest).
So while I am viewing the record for this particular client, I want to update
my comments, preserving the 2 most recent updates. So, I need to move move
Comment2 to Comment3, Comment1 to Comment2 and then clear Comment1. I have a
button which executes a macro running a simple update query, but it updates
the ENTIRE TABLE, not just this record. I do not know VB so I use macros for
everything. I do know SQL.

Any help appreciated.
 
H

Hansford cornett

I think it depends on what your doing.

Lets assume their is a EmpID number on the record.

The macro runs a query. In the EmpId field of the query in the criteria
section in design view place the following code.

= Forms!Formname.EmpID

Dwight

T
 
T

tina

since you're using an Update query, include the table's primary key field in
the query and set a criteria on that field as

Forms!MyFormName!PrimaryKeyFieldName

substitute the correct names for the field and the form that the macro is
being called from.

hth
 
A

AccessNovice2005 via AccessMonster.com

The query works when I use the Forms!MyFormName!FieldName and says it is
updating 1 record (the only record that matches) and I get no errors. But it
doesn't actually change the data. Is the record "locked" or something?
since you're using an Update query, include the table's primary key field in
the query and set a criteria on that field as

Forms!MyFormName!PrimaryKeyFieldName

substitute the correct names for the field and the form that the macro is
being called from.

hth
Need Help.
[quoted text clipped - 14 lines]
Any help appreciated.
 
L

Lynn Trapp

Would you post the entire SQL statement for your query?

--
Lynn Trapp
MS Access MVP
www.ltcomputerdesigns.com
Access Security: www.ltcomputerdesigns.com/Security.htm
Jeff Conrad's Access Junkie List:
http://home.bendbroadband.com/conradsystems/accessjunkie.html



AccessNovice2005 via AccessMonster.com said:
The query works when I use the Forms!MyFormName!FieldName and says it is
updating 1 record (the only record that matches) and I get no errors. But
it
doesn't actually change the data. Is the record "locked" or something?
since you're using an Update query, include the table's primary key field
in
the query and set a criteria on that field as

Forms!MyFormName!PrimaryKeyFieldName

substitute the correct names for the field and the form that the macro is
being called from.

hth
Need Help.
[quoted text clipped - 14 lines]
Any help appreciated.
 

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

Top