Link to home
Start Free TrialLog in
Avatar of Michael Dean
Michael DeanFlag for United States of America

asked on

Duplicate record Wizard not producing correct results.

I have attached my sample database.  If you click on a record on the main screen it will bring you to the Case Details screen.  When you click on "create Additional Review" button it creates a new record however the fileno (automatically created) does not change, which is causing a problem. The fileno is the text box to the right of the Act 6 check box.  I want that number to change when I execute the macro "create additional Review".

The database does not contain any confidential information.
DMC-Backup-Backup.accdb
ASKER CERTIFIED SOLUTION
Avatar of Sheils
Sheils
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Scott McDaniel (EE MVE )
Your database won't open - it's looking for "C:\DMCACS\DMC_Backpu_Backup_be.accdb", which of course does not exist on anyone else's machine.

Make all your tables local, then upload it again.

Also, be sure to Compact your database before uploading.

I can't see the Nav Pane either, and I cannot resize it. That may be because of the path error, but be sure that the database is easily usable, and accessible, before uploading it again.
Avatar of Michael Dean

ASKER

I attached both the FE and BE versions of the database so you can link them locally.  

Thanks for all your help
DMC-Backup-Backup.accdb
DMC-Backup-Backup-be.accdb
You use this code to write a FileNo in the Form's BeforeUpdate event:

If Me.NewRecord Then
    Me.FileNo = Year(Date) & "1" & Format(Me.InvoiceID, "00000")
End If

You could use the same code in your "Create Additional Review" button to write a new fileno. Of course, the code above does not take into account whether the calculated value would already exist, so you may need to change that if you want unique FileNo values.

I'd also suggest you get away from macros. VBA is the language to use unless you're creating apps for your use only (and you can handle the errors that inevitably occur).
Scott

I already have the Beforeupdate event set to that if statement.  SO when I execute the Wizard it copies the FileNo and then doesn't think its a new record so the beforeUpdate event does not run.  So I have a duplicate number created

How would I Put that command into the macro itself?
then doesn't think its a new record so the beforeUpdate event does not run
The Before Update event runs every time you add or update a record, so I think you mean that the "If Me.NewRecord" test does not pass.

If your goal is to create a new record, then get rid of the macro, and do it the right way:

1) Open a recordset that contains the values you want to use for the copy - for example:

Dim rst As DAO.Recordset
Set rst = Currentdb.OpenRecordset("SELECT * FROM YourTable WHERE IDField=" & Me.IDField)

2) Now create a new record:

DoCmd.RunCommand acCmdRecordsGoToNew

3) Now insert values:

Me.txControl1 = rst("Col1")
Me.txControl2 = rst("Col2")

When you do this, you could then run your code that creates the FileNo.

You should never use copy and paste to create records in a database.