Page 1 of 2 12 LastLast
Results 1 to 15 of 29
  1. #1
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Image Code (A2k)

    I've been trying to solve this all afternoon, and only got part way.
    Scenario:

    cmdLoadImages calls frmImages and checks if a record exists;

    Private Sub cmdLoadImages_Click()
    'On Error GoTo errtrap
    Dim db As DAO.Database
    Dim rst As DAO.Recordset
    Dim strFilter As String
    Dim strSQL As String
    Dim strValue As String
    Set db = CurrentDb
    strFilter = "tblImage.EstimateNo = " & Forms!frmDetails!EstimateNo & " And tblImage.Supp = " & Forms!frmDetails.Supp
    strSQL = "Select * From tblImage Where " & strFilter
    Set rst = db.OpenRecordset(strSQL, dbOpenDynaset)
    If rst.RecordCount = 0 Then
    DoCmd.OpenForm "frmImages"
    'Forms!frmImages.Caption = "Details For" & " " & Forms!frmDetails.[EstimateNo] & " / " & Forms!frmDetails.[Supp]
    DoCmd.GoToRecord acDataForm, "frmImages", acNewRec
    'Forms!frmImages!txtRegistration.SetFocus
    'Forms!frmImages!EstimateNo = Forms!frmDetails!EstimateNo
    'Forms!frmImages!Supp = Forms!frmDetails!Supp
    'DoCmd.Close acForm, Me.Name, acSaveNo
    Else
    DoCmd.OpenForm "frmImages", acViewNormal, , strFilter
    Forms!frmImages.Caption = "Details For" & " " & Forms!frmImages.[EstimateNo] & " / " & Forms!frmImages.[Supp]
    'DoCmd.Close acForm, Me.Name, acSaveNo
    End If
    'errtrap:
    Exit Sub
    End Sub


    frmImages Open Event:

    Private Sub Form_Open(Cancel As Integer)
    DoCmd.Close acForm, "frmCreateEstimate", acSaveNo
    Me.lstPreviewJpgs.Requery
    Me.lstPreviewJpgs.SetFocus
    End Sub


    frmImages On Current Event

    Private Sub Form_Current()
    On Error GoTo HandleErr
    Dim rst As Object
    Set rst = Me.RecordsetClone
    rst.MoveFirst
    rst.MoveLast
    Me.txtPicCount = "Image " & (rst.RecordCount - Me.CurrentRecord + 1) & " Of " & rst.RecordCount
    Me.lstPreviewJpgs.Requery
    If Not IsNull([PicFile]) Then
    Me.[imgPicture].Picture = [PicFile]
    'SysCmd acSysCmdSetStatus, "Image: '" & [PicFile] & "'."
    Else
    '[imgPicture].Picture = ""
    ' SysCmd acSysCmdClearStatus
    End If
    Exit Sub
    HandleErr:
    If Err = 2220 Then
    '[imgPicture].Picture = ""
    SysCmd acSysCmdSetStatus, "Can't open image: '" & [PicFile] & "'"
    Else
    MsgBox Err.Description, vbExclamation
    End If
    End Sub


    Function ListJPGS

    Function ListJPGs(fld As Control, id As Variant, _
    row As Variant, col As Variant, _
    Code As Variant) As Variant
    Static dbs(127) As String, Entries As Integer
    Dim ReturnVal As Variant
    Dim strLeft5 As String
    strLeft5 = Left(Forms!frmImages.[EstimateNo], 5)
    ReturnVal = Null
    Select Case Code
    Case acLBInitialize ' Initialize.
    Entries = 0
    dbs(Entries) = Dir("C:BICimage" & strLeft5 & "*.jpg")
    Do Until dbs(Entries) = "" Or Entries >= 127
    Entries = Entries + 1
    dbs(Entries) = Dir
    Loop
    ReturnVal = Entries
    Case acLBOpen ' Open.
    ' Generate unique ID for control.
    ReturnVal = Timer
    Case acLBGetRowCount ' Get number of rows.
    ReturnVal = Entries
    Case acLBGetColumnCount ' Get number of columns.
    ReturnVal = 1
    Case acLBGetColumnWidth ' Column width.
    ' -1 forces use of default width.
    ReturnVal = -1
    Case acLBGetValue ' Get data.
    ReturnVal = dbs(row)
    Case acLBEnd ' End.
    Erase dbs
    End Select
    ListJPGs = ReturnVal
    If ListJPGs = 0 Or ListJPGs = Null Then
    MsgBox "There no Images To Import", vbInformation, ""
    'DoCmd.Close acForm, "frmImages", acSaveNo
    End If
    End Function


    When the form is called, and there is no data, the msgbox from ListJPGS should prevent the form from opening.
    It's pointless opening the form unless there are images already to look at, so we tell the user to import them first.
    I Thought this would be the best way of preventing records being created unless there are records in the folder C:BicImage:

    At the moment, the form still loads, but the "DoCmd.Close acForm, "frmImages", acSaveNo" errors out because the form hasn't loaded yet.
    Should I have used an acDialog instead ??
    I'm taking the oportunity to clean up some code, so if anything else is obvious, is it obvious ??

    (Sorry for the long post)

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Image Code (A2k)

    Dave,

    ListJPGs is a very specialized type of function named a callback function. It is used to populate, format and use the list box; you can't use it for other purposes. So you will have to test elsewhere. I suggest to check for the existence of images in cmdLoadImages_Click on the calling form, and to exit this procedure if there are none.

    1. Remove the following from ListJPGs:

    If ListJPGs = 0 Or ListJPGs = Null Then
    MsgBox "There no Images To Import", vbInformation, ""
    'DoCmd.Close acForm, "frmImages", acSaveNo
    End If

    2. Add the following to cmdLoadImages_Click immediately after the declarations:

    Dim strLeft5 As String
    strLeft5 = Left(Forms!frmDetails.[EstimateNo], 5)
    If Dir("C:BICimage" & strLeft5 & "*.jpg") = "" Then
    MsgBox "There are no images to import", vbInformation
    Exit Sub
    End If

    HTH

  3. #3
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Image Code (A2k)

    I didn't examine the code closely, but if your listbox is populated at the time the form opens, then you should be able to use the .ListCount property of the listbox to tell you whether it has any rows in it.
    Charlotte

  4. #4
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Image Code (A2k)

    Works like a dream.
    Thanks again Hans

    Have a good day

    Charlotte, Thanks for the reply, I've used Hans's suggestion, it works so I won't mess with it now. <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>

  5. #5
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Image Code (A2k)

    Hans
    Sorry, have I missed something ? Three Scenario's here:

    The images are stored in C:BicImage.
    When the form loads, and no images are in the folder, the code works ok and prevents the form loading.

    The table has images for the current record, the form opens and all the images can be seen.But:
    lstPreviewJPGs is not populated.

    No records in the table, but image in the folder:
    I get Access error "No Current Record"

    Seems like on the third option, the record is not created yet.

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Image Code (A2k)

    Dave,

    If the list box is not populated, check ListJPGs very carefully to see if there are no errors in the path etc.. You might try to single step through it, but that is very tedious because the function gets called a lot of times.

    All in all, there are so many variables in this equation (tables, forms, folders) that it is hard to say from a distance what is happening and what might go wrong. It might be a good idea to take a copy of the database and try to break the problem into smaller pieces. For instance, just try to populate the list box, without worrying about all the conditions.

  7. #7
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Image Code (A2k)

    Hans
    As you say, there are many instances in which the code is called, I'm just going round in circles trying to find whats happening.
    I've re-created as much as I can with the attachment. I've put the forms module in a memo field in table "formmodule", perhaps you can see something more obvious.

    Meanwhile, I'll keep looking at this end.
    Attached Files Attached Files

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Image Code (A2k)

    Dave,

    It will take some time to investigate this, don't expect an answer real soon.

  9. #9
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Image Code (A2k)

    Hans
    I'm not going anywhere !! <img src=/S/evilgrin.gif border=0 alt=evilgrin width=15 height=15>

  10. #10
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Image Code (A2k)

    The first problem was easier than I thought. You have inadvertently removed the line

    ListJPGs = ReturnVal

    from the ListJPGs function, immediately above End Function. So the function doesn't return anything any more. If you put the line back, the list box should be populated again.

  11. #11
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Image Code (A2k)

    <img src=/S/blush.gif border=0 alt=blush width=15 height=15> I've always been dangerous with a <img src=/S/mouse.gif border=0 alt=mouse width=42 height=33>

    One down, ## to go.

  12. #12
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Image Code (A2k)

    Next one:

    In the Form_Current event of frmImages, you have

    Set rst = Me.RecordsetClone
    rst.MoveFirst

    If there are no images in the table, rst is empty, so rst.MoveFirst raises an error (No current record). To avoid this, insert a line above it (and below Set rst = ...):

    If rst.EOF Then Exit Sub

    Note: it is not necessary to requery lstJPGs in Form_Current (or in Form_Open)

  13. #13
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Image Code (A2k)

    Hans

    Great minds think alike.
    I am in the current event at the moment and dwindling out parts of code as we speak.
    I stepped thru and saw the RST's were creating a problem and also the requery statement is rather pointles.
    On refining this, when closing the form, listJPGs stumbles on a "Can't Find Forms!frmImages...................
    I think that might be one of the requery faults aswell.

    Thanks for looking, I am still working at it and hope shortly to solve it.

  14. #14
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Image Code (A2k)

    1. Comment out *all* instances of lstJPGs.Requery. You can always uncomment them later if needed.
    2. Replace Forms!frmImages in ListJPGs by CodeContextObject. Don't know if that will help, but it shouldn't hurt.

  15. #15
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Image Code (A2k)

    Hans
    CodeContextObject works ok.

    All Instances of requery commented out.
    Where does the first requery need to be ? to start the ball rolling.

Page 1 of 2 12 LastLast

Posting Permissions

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