Consulting

Results 1 to 13 of 13

Thread: DoCopy access Table -- Duplicating Records

  1. #1

    DoCopy access Table -- Duplicating Records

    Hi, I am still very new to VBA especially in Access. What I am trying to do is use a form with buttons (with code) that copies a table and pastes it with today's date. So that the user doesn't overwrite the data each time they import a new file. It works however it is duplicating the records in the table and can't seem to figure out why.

    The form has 3 buttons
    - Step 1 Copy & Paste
    - Step 2 Import
    - Step 3 Rename & Exports the file to a network folder

    Step 1 -- code is as follows
    [Private Sub Command2_Click()

    DoCmd.CopyObject , "ShipStatusFm_ExportList_previous_" & Format(Date, "mmddyy"), acTable, "ShipStatusFm_ExportList"
    ]

    Any help is greatly appreciated.




    [/CODE]
    Last edited by melgra2017; 11-12-2018 at 10:05 AM. Reason: didn't finish

  2. #2
    VBAX Guru
    Joined
    Mar 2005
    Posts
    3,296
    Location
    I am not sure I completely understand what you are actually doing.
    However to prevent duplication there should be some kind of "flag" or indicator in the table to prevent duplicated effort.
    There should also be a Master Key field which also prevents record duplication.

  3. #3
    All I am trying to do is copy the source data table before the new data is imported an overwrites the table.

  4. #4
    VBAX Guru
    Joined
    Mar 2005
    Posts
    3,296
    Location
    Is the new data an "updated" version of the original data, or completely new data?

  5. #5
    It will be new updated each month of the original. Try to make sure I can go back if the user has issues.

  6. #6
    VBAX Guru
    Joined
    Mar 2005
    Posts
    3,296
    Location
    If the table is not too large I would suggest that you have an Archive table, this can be updated prior to each import by an Append Query that adds the current data to the Archive table and then runs a Delete query that removes the records in the current table.
    The Archive table would have an extra field for the Date of transfer so that you can call up the records for a particular month.
    The Archive table could even be in a separate Archive database if required.

  7. #7
    VBAX Newbie
    Joined
    Nov 2018
    Posts
    2
    Location
    I have a rather complex problem I am working on and would appreciate any help I can get. I work at an electronics manufacturing place and we create electronic boards and assemblies. One of the tasks assigned are to do crimps. I have to make a form that, when a person enters the crimp height measurement it checks that value against the standard crimp Lo/Hi for that measurement. If it meets the standard, then the person can continue with finishing the assembly, otherwise it should stop them and not allow them to go any further and to alert them to seek a supervisor. The problem I am encountering is that there may be multiple crimp numbers associated with the different gauges.

    Here is an example: For Crimp # PA74-0000-96 there are two crimp assemblies that utilize 12AWG (which the standard is 0.096" + 0.002). None use the crimp #208-060, 12AWG (where the standard is also 0.096+ 0.002) and 108 different assemblies use Crimp # 208-032, 12AWG (standard 0.071"+ 0.002).

    Here is what I have written for code so far but I can't seem to get it to run.


    Function InTolerance(Gauge, CrimpHeight)
    Dim CrimpHeight As Double 'Declare variable as data type
    Dim Gauge As String
    Dim CrimpNum As String
    Dim Prompt, CrimpNum, Gauge



    Gauge = "AWG Standard(CrimpHeightLo,CrimpHeightHi)"

    Prompt = "Crimp #:"
    Prompt = "Gauge Used:"

    CrimpNum = InputBox$(Prompt)
    Label1.Caption = CrimpNum
    Label2.Caption = Gauge

    Select Case Gauge ' Ensure correct Gauge is matched with crimp# to get correct Lo and Hi standard for that crimp#/AWG
    where CrimpNum = CrimpNum(Gauge)
    Eval (IIf(CrimpHeight >= CrimpHeightLo And CrimpHeight <= CrimpHeightHi, CrimpNum = CrimpNum(Gauge) Or CrimpNum(Gauge) = "N/A"))
    Else
    CrimpNum = CrimpNum
    End Select


    If CrimpHeight >= CrimpHeightLo And CrimpHeight <= CrimpHeightHi Then 'Evaluate whether or not CrimpHeight number is between Lo/Hi values; color green
    MsgBox ("Ok, you are good to proceed.")
    TxtColor Green
    Else
    If CrimpHeight <= CrimpHeightLo And CrimpHeight >= CrimpHeightHi Then 'Evaluate whether or not CrimpHeight number is outside Lo/Hi values; color Red
    MsgBox ("STOP! Do Not Proceed! Please see Supervisor.")
    TxtColor Red

    End Function


    In the form itself I put: SELECT CrimpNum, Gauge, CrimpHeight, fnInTolerance(Gauge, CrimpHeight) as Tolerance
    FROM tblCrimps

  8. #8
    That was my next step. However, I was trying to use VBA to get more familiar with it. Thanks for the help.

  9. #9
    VBAX Guru
    Joined
    Mar 2005
    Posts
    3,296
    Location
    Hello, instead of Prompts I would probably use Combo boxes to select required Crimp # and Gauge Used.
    What is not working in your code.
    ps Your code does not have any Error trapping, should one occur.

  10. #10
    VBAX Guru
    Joined
    Mar 2005
    Posts
    3,296
    Location
    OK, Learning VBA is good, but where & when to apply it is also essential for smooth operation.
    Do you need further assistance?

  11. #11
    No, I’m good.

  12. #12
    VBAX Newbie
    Joined
    Nov 2018
    Posts
    2
    Location
    On the form, crimp # and gauge are combo boxes. It's when a person enters a crimp height that I have to validate against what they entered to what the standard is to tell them whether or not they need to stop and get a supervisor.

  13. #13
    VBAX Guru
    Joined
    Mar 2005
    Posts
    3,296
    Location
    lmeser61, I notice that you are using a function for your code.
    I would use the Combo's "After Update" Event Procedure for the code .

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •