Image field

dbertanjoli

Registered User.
Local time
Today, 20:15
Joined
Sep 22, 2000
Messages
102
I am building a small patient database. I have a field called imagepath that holds links to the images. This field is on my subform. So whenever I add new path/image in my form I am sent to my first record instead of staying on the current record. How this can be resolved?

Many thanks,
Debbie
 
Current record problem

Many thanks for your reply.
I checked the thread but my problem is different.

I have a PhotoLink field that stores the path to the image.

To add an image to the form I need to click on the "Add Image" button. This opens up the Browse Files dialog box and allows me to browse for an image file on my system.

Once I select a file, this inserts the filepath name into the Photo text box and this is where my problem begin. After adding/inserting image I am sent back to my first record instead of going back to my current record where the last image is actually inserted. Please let me know if there is a solution for this problem?

Many thanks,
Debbie
 
what is the code behind your insert command?
 
Hello,
Here is my function:

Function setImagePath()
Dim strImagePath As String
On Error GoTo PictureNotAvailable
strImagePath = Me.memProperyPhotoLink
Me.memProperyPhotoLink.Locked = True
Me.memProperyPhotoLink.Enabled = False
Me.ImageFrame.Picture = strImagePath
Exit Function
PictureNotAvailable:
strImagePath = "C:\DataBase\NoImage.gif"
Me.ImageFrame.Picture = strImagePath

End Function



and this is what is called ufter update:

Private Sub memProperyPhotoLink_AfterUpdate()
setImagePath
Forms![frmProperties].Form.Requery



End Sub
 
I suspect your
Forms![frmProperties].Form.Requery
is your problem. Try commenting it out and see what happens.
 
Hello,
I tried, but nothing has changed?? This is driving my crazy. Also I have 4 tab buttons and I would like after moving to new record to set focus on my first tab. Now what happen is if I am using my second tab and move to the next record the focus is still on the second tab of my new record? Any suggestions?

Debbie
 
Let's work on one problem at a time. Are your forms synched?
 
They are. I even tried putting everyting on one form and still keep sending me back to the first record after uploading image.

Here is my module. It might be something wrong with it:

Option Compare Database
Option Explicit

'.
' ADDITIONAL NOTES:
'
' This module only provides the Open/Save file dialog, not the other
' CommonDialog interfaces (ColorChooser, Help, PrintDialog, etc.)
'
' If you want your user to browse for folder names (paths) you must use
' the module basBrowseFolders instead.
'
' TO STREAMLINE this module for production programs, you should remove:
' 1) Unnecessary comments
' 2) Flag Constants which you do not intend to use.
' 3) The test procedure tsGetFileFromUserTest
'
'--------------------------------------------------------------------------
'
' INSTRUCTIONS:
'
' ( For a working example, open the Debug window )
' ( and enter tsGetFileFromUserTest. )
'
'.All the arguments for the function are optional. You may call it with no
'.arguments whatsoever and simply assign its return value to a variable of
'.the Variant type. For example:
'.
'. varFileName = tsGetFileFromUser()
'.
'.The function will return:
'. the full path and filename selected or entered by the user, or
'. Null if an error occurs or if the user presses Cancel.
'.
'.Optional arguments may include any of the following:
'. rlngFlags : one or more of the tscFN* constants (declared below)
'. Combine multiple constants like this:
'. tscFNHideReadOnly Or tscFNFileMustExist
'. strInitialDir : the directory to display when dialog opens
'. strFilter : a string containing any filters you want to use. Each
'. part must be separated by the vbNullChar. -example below
'. lngFilterIndex: a 1-based index indicating which filter to start with.
'. strDefaultExt : Extension to use if user does not enter one.
'. strFileName : Default File to display in the File Name text box.
'. strDialogTitle: Caption to display in the dialog's title bar.
'. fOpenFile : Boolean-True for the Open dialog, False for Save dialog.
'
' FILTER EXAMPLE: The filter must be a string containing two parts for each
' filter. The first part is the Description, it is what the user will see
' in the Files of Type box, e.g. "Text Files (*.txt)". The second part is
' the actual filter, e.g. "*.txt". Each part and each filter must be
' separated by the vbNullChar. For example, to provide two filters, one for
' *.mdb files, and one for all files, use a statement like this:
'
' strFilter = "Access (*.mdb)" & vbNullChar & "*.mdb" _
' & vbNullChar & "All Files (*.*)" & vbNullChar & "*.*"
'
' Then pass your strFilter variable as the strFilter argument for the call
' to tsGetFileFromUser()
'
'.--------------------------------------------------------------------------
'.

Private Declare Function ts_apiGetOpenFileName Lib "comdlg32.dll" _
Alias "GetOpenFileNameA" (tsFN As tsFileName) As Boolean

Private Declare Function ts_apiGetSaveFileName Lib "comdlg32.dll" _
Alias "GetSaveFileNameA" (tsFN As tsFileName) As Boolean

Private Declare Function CommDlgExtendedError Lib "comdlg32.dll" () As Long

Private Type tsFileName
lStructSize As Long
hwndOwner As Long
hInstance As Long
strFilter As String
strCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
strFile As String
nMaxFile As Long
strFileTitle As String
nMaxFileTitle As Long
strInitialDir As String
strTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
strDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type

' Flag Constants
Public Const tscFNAllowMultiSelect = &H200
Public Const tscFNCreatePrompt = &H2000
Public Const tscFNExplorer = &H80000
Public Const tscFNExtensionDifferent = &H400
Public Const tscFNFileMustExist = &H1000
Public Const tscFNPathMustExist = &H800
Public Const tscFNNoValidate = &H100
Public Const tscFNHelpButton = &H10
Public Const tscFNHideReadOnly = &H4
Public Const tscFNLongNames = &H200000
Public Const tscFNNoLongNames = &H40000
Public Const tscFNNoChangeDir = &H8
Public Const tscFNReadOnly = &H1
Public Const tscFNOverwritePrompt = &H2
Public Const tscFNShareAware = &H4000
Public Const tscFNNoReadOnlyReturn = &H8000
Public Const tscFNNoDereferenceLinks = &H100000

Public Function tsGetFileFromUser( _
Optional ByRef rlngflags As Long = 0&, _
Optional ByVal strInitialDir As String = "", _
Optional ByVal strFilter As String = "All Files (*.*)" & vbNullChar & "*.*", _
Optional ByVal lngFilterIndex As Long = 1, _
Optional ByVal strDefaultExt As String = "", _
Optional ByVal strFileName As String = "", _
Optional ByVal strDialogTitle As String = "", _
Optional ByVal fOpenFile As Boolean = True) As Variant

On Error GoTo tsGetFileFromUser_Err
Dim tsFN As tsFileName
Dim strFileTitle As String
Dim fResult As Boolean

' Allocate string space for the returned strings.
strFileName = Left(strFileName & String(256, 0), 256)
strFileTitle = String(256, 0)

' Set up the data structure before you call the function
With tsFN
.lStructSize = Len(tsFN)
.hwndOwner = Application.hWndAccessApp
.strFilter = strFilter
.nFilterIndex = lngFilterIndex
.strFile = strFileName
.nMaxFile = Len(strFileName)
.strFileTitle = strFileTitle
.nMaxFileTitle = Len(strFileTitle)
.strTitle = strDialogTitle
.flags = rlngflags
.strDefExt = strDefaultExt
.strInitialDir = strInitialDir
.hInstance = 0
.strCustomFilter = String(255, 0)
.nMaxCustFilter = 255
.lpfnHook = 0
End With

' Call the function in the windows API
If fOpenFile Then
fResult = ts_apiGetOpenFileName(tsFN)
Else
fResult = ts_apiGetSaveFileName(tsFN)
End If

' If the function call was successful, return the FileName chosen
' by the user. Otherwise return null. Note, the CancelError property
' used by the ActiveX Common Dialog control is not needed. If the
' user presses Cancel, this function will return Null.
If fResult Then
rlngflags = tsFN.flags
tsGetFileFromUser = tsTrimNull(tsFN.strFile)
Else
tsGetFileFromUser = Null
End If

tsGetFileFromUser_End:
On Error GoTo 0
Exit Function

tsGetFileFromUser_Err:
Beep
MsgBox Err.Description, , "Error: " & Err.Number _
& " in function basBrowseFiles.tsGetFileFromUser"
Resume tsGetFileFromUser_End

End Function

' Trim Nulls from a string returned by an API call.

Private Function tsTrimNull(ByVal strItem As String) As String

On Error GoTo tsTrimNull_Err
Dim I As Integer

I = InStr(strItem, vbNullChar)
If I > 0 Then
tsTrimNull = Left(strItem, I - 1)
Else
tsTrimNull = strItem
End If

tsTrimNull_End:
On Error GoTo 0
Exit Function

tsTrimNull_Err:
Beep
MsgBox Err.Description, , "Error: " & Err.Number _
& " in function basBrowseFiles.tsTrimNull"
Resume tsTrimNull_End

End Function
 
I don't see anything here that would be causing that problem. What code is on the click event of your add image?
 
Hello,
here is the code on click event to add image:

Private Sub cmdAddImage_Click()
On Error GoTo cmdAddImage_Err
Dim strFilter As String
Dim lngflags As Long
Dim varFileName As Variant

strFilter = "All Files (*.*)" & vbNullChar & "*.*" _
& vbNullChar & "All Files (*.*)" & vbNullChar & "*.*"

lngflags = tscFNPathMustExist Or tscFNFileMustExist _
Or tscFNHideReadOnly

varFileName = tsGetFileFromUser( _
fOpenFile:=True, _
strFilter:=strFilter, _
rlngflags:=lngflags, _
strDialogTitle:="Please choose a file...")

If IsNull(varFileName) Then
Else
Me![memProperyPhotoLink] = varFileName
Forms![frmProperties].Form.Requery
End If

cmdAddImage_End:
On Error GoTo 0
Exit Sub

cmdAddImage_Err:
Beep
MsgBox Err.Description, , "Error: " & Err.Number _
& " in file"
Resume cmdAddImage_End
End Sub
 
Hello again,
I commented out this line
Forms![frmProperties].Form.Requery
from on click event to add image and now is working but is not adding image to the image frame until I move to the next record? Any comment on this and also my previous question on tab focus.

Very grateful for all your help.

Debbie
 
You need to set the picture property put this where you had the
Forms![frmProperties].Form.Requery on your add button.

Me.ImageFrame.Picture = strImagePath
 
I will not be able to help on the tab focus issue. I'm sure there is a way.
 
Many thanks for all your help. But this last line didn't solve the problem. I still can't see an image until I move to the next or previous record????

Deb
 
Sorry I did not properly read through all your code. I'm pretty sure this will work. Call your Function setImagePath there instead like so.

Call setImagePath
 
Try after you set the image to immediately do a me.repaint
 
In an identical situation, I found a Me.Refresh did the job, though a Me.Repaint did not.

(Apologies for bringing up an old thread, hoped someone might benefit from the small amount of additional wisdom!)
 
Try bookmark your record before the sending the requery. This will allow you to go back to the record you were working before. Search the forum for it. I had the same problem.
 

Users who are viewing this thread

Back
Top Bottom