> I am using an Append Query run by a Macro which does successfuly copy the
old
> record over. However SetWarnings to No in the macro is not supported by
> Access 2007 which creates compatiblity issues.
How about ditching your code below and bringing the Append query into VBA?
In that case, it's a one-liner:
CurrentDb.Execute "YourQuery"
And for the warnings, it turns into 3 lines (I'm pretty sure this still
works in 07, but I use 03)
DoCmd.SetWarnings(False)
CurrenDB.Execute "YourQuery"
DoCmd.SetWarnings(True)
Just be sure to put a SetWarnings(True) in your exit code, just in case
something goes wrong and the error handler is called, in which case the line
after your Execute may not run. In fact, I make it a standard to put
SetWarnings(True) right in my error handler, just in case. (This may be the
reasoning behind Access pulling this feature out from macros in '07 - there's
no way to catch it using a macro).
Also, check into the vbFailOnError constant as an argument to Currendb.Execute
This should be all you need to accomplish what you are looking for.
Expecially easy if the query already runs from a macro... just move the query
to VB.
Only, the only macro I will ever use is AutoExec. They just plain don't
have the versitility that vb does.
If changing the macro calls to vb functions calls will be troublesome
throughout the entire db, you can 'cheat' a little, and leave the macro, but
change it to RunCode() and then put your code for setwarnings/append query in
a function called by the macro. If you've got say 20 places in a
pre-existing db this might save a little bit of headache, though it isn't
very elegant.
hth
--
Jack Leach
www.tristatemachine.com
- "Success is the ability to go from one failure to another with no loss of
enthusiasm." - Sir Winston Churchill
"J.J." wrote:
> I am using an Append Query run by a Macro which does successfuly copy the old
> record over. However SetWarnings to No in the macro is not supported by
> Access 2007 which creates compatiblity issues.
> I tried Allen Browne's code but it is too complex for me to edit. I am still
> tinkering with the following code that won't run. I hate to be a pain but I
> have something wrong. Any ideas please?
>
> Dim strSearch As String
> Dim ctl As Control
> ' form is open with data source set to secondary table "IntakeData"
> Set rst = Me.RecordsetClone
> ' set string value for match up where ClientID is primary key of "Client"
> table linked
> ' to secondary table "IntakeData"
> strSearch = str(Me!ClientID)
> ' find a match preferably the last record ( try FindLast?) that has the same
> ' ClientID as current form
> rst.FindFirst "ClientID= " & strSearch
> If rst.NoMatch Then
> ' There is no record match & nothing happens so tell user no cigar
> MsgBox "No Previous Record Exists. Unable to Duplicate."
> Else
> ' copy all the data over from previous record to current record
> For Each ctl In Me.Controls
> ' need to copy all records except of course the old IntakeID
> ' there must be a more effcient means to copy all but the
> ' IntakeID besides having to tag all other fields?
> If ctl.Tag = "RepeatPrevious" Then
> ' copy old field value to new field value
> ctl.Value = .Fields(ctl.IntakeDta)
> End If
> Next
> End If
> ' All records are copied now but still need code here to refresh open
> form?
> ' this lets user add or edit before moving on
> Exit_Dupli_Click: etc etc.