MK-macro-like

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Most times, when I use form a, I click on a command button which opens sub
form B as a front end to table B. table A has autonumber as a primary key
(unique) and table B has "number" as a pseudo-key (not unique but required ;
duplicates allowed) in a one to many relationship. Table B has recordtypename
as a field. Table B usually has 4 to 10 records related to each unique table
A entry. 95% of the time, I click on the command button, and create 6
records in table B: recordtypename A, recordtypename B,recordtypename C,
recordtypename D,recordtypename E,recordtypename F. This takes a few seconds
and is annoying because it is so predictably repititious. I want to handle
this work like a macro of sorts. When I click the commandbutton, I have some
underlying code in CODEBUILDER that says
create record one ,
SET recordtypename = A and leave the other fieldnames unpopulated,
create record two , SET recordtypename = B and leave the other fn
unpopulated, create record three , SET recordtypename = C and leave the other
fn unpopulated,
:
:
create record six , SET recordtypename = F and leave the other fn unpopulated

Then 5 % of the time, I could just delete the record I don't need.

I am not clear on how to write the code.
 
You could do this by running an append query using vba on
the cmd button that opens form B _before_ opening form B.
If the form opens before the query has finished then that
form will not show all or less of the new records.

Use the query builder to create an append query that does
what you want. Test it manually. Save the query.

Now you've a couple of ways to do this:-
Either run the query that you just saved or copy the SQL of
that query to the clipboard (from SQL view in the query
designer) and then run that SQL.

DoCmd is the command you're after -

DoCmd.OpenQuery "YourSavedQueryName"

or

DoCmd.RunSQL "Pasted SQL Statement"

You should also look up the SetWarnings Method for DoCmd in
the help. If you use it to turn warnings off (False) make
sure you turn them back on again (True) at the end of your
code.

Good luck

--
Nick Coe (UK)
http://www.alphacos.co.uk/ AccHelp + pAnimal
http://www.pjandcoe.co.uk/ Online Store
http://www.mrcomputersltd.com/ Repairs Upgrades

In mark r typed:
 
Back
Top