Extra records added to table

RickRo

Registered User.
Local time
Today, 02:47
Joined
Mar 16, 2013
Messages
18
My intent with the code below is to copy the Me.Serial value into the hostname, than check the Me.Serial value and if it begins with PDS, strip that off and write the new number as Me.Serial.

What happens is I get two record sets in my table - one that has no Me.Serial and the hostname, the other has the stripped Me.Serial and no hostname.

Code:
Private Sub Serial_AfterUpdate()

  Dim MyDB As Database
  Dim hostname As String

  Set MyDB = CurrentDb
  hostname = Me.Serial

    If Me.Serial Like "PDS*" Then
    Me.Serial = Right(Me.Serial, Len(Me.Serial) - 3)

    DoCmd.SetWarnings False
      DoCmd.RunSQL "INSERT INTO tblTemp (tmptoHostname) VALUES ('" & hostname & "')"
    DoCmd.SetWarnings True

    End If

End Sub
 
Possibly your code should look like;
Code:
Private Sub Serial_AfterUpdate()

  Dim MyDB As Database
  Dim hostname As String

  Set MyDB = CurrentDb


    If Me.Serial Like "PDS*" Then
    hostname = Right(Me.Serial, Len(Me.Serial) - 3)

    DoCmd.SetWarnings False
      DoCmd.RunSQL "INSERT INTO tblTemp (tmptoHostname) VALUES ('" & hostname & "')"
    DoCmd.SetWarnings True

    End If

End Sub
 

Users who are viewing this thread

Back
Top Bottom