Results 1 to 2 of 2
  1. #1
    Star Lounger
    Join Date
    Feb 2002
    Thanked 0 Times in 0 Posts

    Image Code (A2000)

    The following code is causing a problem in my db.

    On Error GoTo Errtrap
    DoCmd.GoToRecord acDataForm, "frmImage", acNewRec
    Forms!frmImage!EstimateNo = Forms!frmdetails!EstimateNo
    Forms!frmImage!Supp = Forms!frmdetails!Supp
    Me.cmdlgpicture.InitDir = "L:home"
    Me.cmdlgpicture.Filter = " Image (*.jpg)|*.jpg"
    Me.olepicture.SourceDoc = Me.cmdlgpicture.FileName
    If Me.cmdlgpicture.FileName <> "" Then
    Me.olepicture.SizeMode = acOLESizeStretch
    Me.olepicture.Action = acOLECreateLink
    End If
    Exit Sub

    If their is a record already in the table, it works fine.
    Adds a new record as it should.
    If their is no record and the code is activated,it adds a new record leaving a blank record in the table along with the newly created one.

    I know the cause is the first line "acnew etc" but don't know how to bypass this.

    Ideally, when the form opens and their are no records to start with, a msgbox to tell the user, their are no records, do you want to add would be great.

    Can some-one help


  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Sacramento, California, USA
    Thanked 1 Time in 1 Post

    Re: Image Code (A2000)

    You'll get an error from that first line if you're already on a new record. You'll need to trap it by testing to see if you *are* on a new record something like this:

    If Not Me.NewRecord Then
    DoCmd.GoToRecord acDataForm, "frmImage", acNewRec
    End If
    ... etc.

    I wasn't sure which form the Me operator was referencing, so I went ahead and used it here, although it may not refer to the correct form. If that's the case, you'll need to change that to reference frmImage instead.

Posting Permissions

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