Results 1 to 4 of 4
  1. #1
    billcar2006 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Oct 2014
    Posts
    13

    use if statement or something else

    I am running code to copy a record to a new record
    Private Sub btnCopy_Click()
    Dim ProgramNo As String
    Dim PartName As String
    Dim DRGno As String
    Dim BarType As String
    Dim cbomachine As String
    Dim Combo129 As String
    Dim OperationNumber As String
    Dim TxtDRGno1 As String
    Dim Jaws As String
    Dim ThroughDrillSize As String
    Dim BUNG As String
    'Copy fields to variables


    ProgramNo = Me.[Program No]
    PartName = Me.[Part Name]
    DRGno = Me.DRGno
    BarType = Me.[Bar Type]
    cbomachine = Me.cbomachine
    Combo129 = Me.Combo129
    OperationNumber = Me.[Operation Number]
    TxtDRGno1 = Me.TxtDRGno1
    Jaws = Me.[Jaws & Chuck Jaw Data]
    ThroughDrillSize= Me.[Through Drill Size]
    BUNG = Me.BUNG

    'Go to a new record
    DoCmd.GoToRecord , , acNewRec

    'Reverse the process and plug old values into new record

    Me.[Program No] = ProgramNo
    Me.[Part Name] = PartName
    Me.DRGno = DRGno
    Me.[Bar Type] = BarType
    Me.cbomachine = cbomachine
    Me.Combo129 = Combo129


    Me.[Operation Number] = OperationNumber
    Me.TxtDRGno1 = TxtDRGno1
    Me.[Jaws & Chuck Jaw Data] = Jaws
    Me.[Through Drill Size] = ThroughDrillSize
    Me.BUNG = BUNG
    End Sub

    It seems that if any of these entries are empty it throws up a debug error for the code on the line that's copying the entry to the string
    ie. TxtDRGno1 = Me.TxtDRGno1. if there is an entry, the same code works fine and copies the entry.
    My question is can an if statement be added that checks if the entry id blank and doesn't run TxtDRGno1 = Me.TxtDRGno1, but if there is an entry it then runs the code.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    If you change your variables to Variant rather than String, the code will probably work as is.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    billcar2006 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Oct 2014
    Posts
    13
    Thanks, that worked great.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. if statement in sql statement, query builder
    By 54.69.6d.20 in forum Access
    Replies: 4
    Last Post: 09-11-2012, 07:38 AM
  2. Which statement to use
    By kpo in forum Programming
    Replies: 4
    Last Post: 05-01-2012, 03:53 PM
  3. Replies: 7
    Last Post: 08-17-2011, 01:49 PM
  4. need a If /then statement
    By kmiszczak in forum Access
    Replies: 1
    Last Post: 04-12-2011, 01:51 PM
  5. SQL like statement?
    By Cojack in forum Queries
    Replies: 4
    Last Post: 09-21-2010, 04:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums