User Control Photo

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Richard Alvarez
    New Member
    • Apr 2011
    • 32

    User Control Photo

    Need help with my code, I use SQL syntax.
    Code:
    Request = "INSERT INTO tblEmployeeInfo VALUES(" & Replace(Me.txtID.Text, "'", "''") & "," & _
         "'" & AccessCode & "'," & _
         "'" & Replace(Me.txtLastName.Text & ", " & Me.txtFirstName.Text _
                                & " " & Me.txtMidleName.Text, "'", "''") & "'," & _
                    "'" & Replace(Me.cboGender.Text, "'", "''") & "'," & _
         "'" & Format(Me.dtpBDate.Value, "MM/dd/yyy") & "'," & _
         "'" & CurrentAge & "'," & _
         "'" & Replace(Me.txtAddress.Text, "'", "''") & "'," & _
         "'" & Replace(Me.txtContact.Text, "'", "''") & "'," & _
         "'" & Replace(Me.txtEmail.Text, "'", "''") & "'," & _
         "'" & Replace(Me.mskFrom.Text, "'", "''") & "'," & _
         "'" & Replace(Me.mskTo.Text, "'", "''") & "'," & _
         "'" & Replace(Me.cboDepartment.Text, "'", "''") & "'," & _
         "'" & Replace(Me.phProfiler.SavePhoto, "'", "''") & "')"
    I use a user control for the photo and i got an Argument not Optional error in this line ""'" & Replace(Me.phPr ofiler.SavePhoto, "'", "''")". Please help me with this. Thanks in advance.
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    what is phProfiler in your code ?

    and what does SavePhoto property stores ?

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      From the sound of it, the SavePhoto function requires an argument. Pure speculation here, but I'd guess that it expects a string containing the name of a file in which to save the photo.

      As debasisdas pointed out, we need more info as to exactly what type of object phProfiler is, and what SavePhoto is/does. The chances are good that in providing that info you'll probably come up with the answer yourself. :-)

      Comment

      • Richard Alvarez
        New Member
        • Apr 2011
        • 32

        #4
        Thank you for your quick replies sir(s). phProfiler here is a user control for displaying photo and PhotoSave is its property of inserting the selected image file within the database as an ole object. What sir killer42 said yes it expects for a string containing the file but still no luck.

        Comment

        • Killer42
          Recognized Expert Expert
          • Oct 2006
          • 8429

          #5
          What happens then, when you supply a string argument to SavePhoto? This seems to be the main problem.
          The way SavePhoto is used here is a bit confusing. Does it also return a string value? If not, then you won't be able to use it in the Replace function in this way.

          One thing I always recommend when debugging is to zero in and isolate the specific piece of code which is producing the problem. So for example, I'd comment out the whole Assignment statement (Request = blah blah...) and just do something like Debug.Print Me.phProfiler.S avePhoto(<your argument>). If you can't get a string out of it, then there's no point trying to use that string in the INSERT and so on.

          (Note that it only requires one ' at the start of the statement to comment out the entire block, not on every line.)

          Comment

          • Richard Alvarez
            New Member
            • Apr 2011
            • 32

            #6
            Thank you again for doing a great job. I had it fixed! instead of using this user control, i just switched to using this code.
            Code:
             Private Sub cmdselect_Click()
            On Error Goto Err_CS:
                'Select an image file to open
                With dlgSelect
                    .CancelError = True
                    .DialogTitle = "Select image..."
                    .Filter = "Image Files (*.jpg, *.bmp, *.gif)|*.jpg;*.bmp;*.gif"
                    .ShowOpen
                    txtImagePath = .FileName
                    If Trim$(txtImagePath.Text) <> "" Then
                        LoadPointerImage (Trim$(txtImagePath.Text))
                    End If
                End With
            
                Exit Sub
                
            Err_CS:
                If Err.Number <> 32755 Then 'User cancelled
                    Err.Raise Err.Number, Err.Source, Err.Description
                    Err.Clear
                End If
            End Sub 
            
            Sub LoadPointerImage(sImage As String)
            
                On Error GoTo Errorhandler:
                'Load the file pointer into the Image control
                If Len(Dir(sImage)) Then
                    picEmployee.Picture = LoadPicture(sImage)
                Else
                    picEmployee.Picture = LoadPicture()
                End If
                PicBlank.Visible = False
                Exit Sub
            Errorhandler:
                Err.Raise Err.Number, Err.Source, "File does not appear to be a valid image file..." & _
                    vbCrLf & vbCrLf & Err.Description
                Err.Clear
            End Sub
            
            Function VerifyAndSave() As Boolean
            
                On Error GoTo Errorhandler:
                Call Info
                Dim strMsg, ans As String
                Dim bytBLOB() As Byte
                Dim strImageTitle As String
                Dim strImagePath As String
                Dim intNum As Integer
            
            
                strImagePath = Trim$(txtImagePath.Text)
                InfoRS.Find "EM_ID='" + txtEM_ID.Text + "'", 0, 1
                    With InfoRS
                        If (txtImagePath.Text <> "") Then
                            'Open the picture file
                            intNum = FreeFile
                            Open strImagePath For Binary As #intNum
                            ReDim bytBLOB(FileLen(strImagePath))
                            
                            'Read the data and close the file
                            Get #intNum, , bytBLOB
                            Close #1
                            .Fields("PICTURE").AppendChunk bytBLOB
            
                       End If
                    .Update
                    End With
            
                Exit Function
            Errorhandler:
                   MsgBox "Error :" & " " & Err.Number & Err.Description, vbCritical
                   Err.Clear
            
            End Function

            Comment

            Working...