Keeping current record on focus

  • Thread starter Secret Squirrel
  • Start date
S

Secret Squirrel

I have a form with a listbox in it that shows all my employees. When I open
the form I have it set to go to the first record in the list and show that
employees record. This is how I have it set up in the open event of my form:

Me.EmployeeList = Me.EmployeeList.ItemData(0)

I have a command button on my form that allows me to add a link to their
picture file. After I click on this command button and select the file it
then reverts back to the first record but in the list box it still highlights
the employee I just added the link to. In order for me to get back to that
record I click on their name again in the listbox and it shows that employees
info.

My question is how can I have it not revert back to the first record in my
table after I run this command? I want to have it stay on that employees
record after I add the link. Here is the code I'm using on my command button:

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

Me.LastName.SetFocus

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![frmEmployeeMain].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
 
A

Albert D. Kallal

Forms![frmEmployeeMain].Form.Requery


Do you need to do a requery here?

If you looking to force a disk write, simple go:

If me.Dirty = True then
me.Dirty = false
end if

The above will force the data to disk for you. I not really sure you need
the requery? (as that will force a complete re-load of the form and movement
to the first record...
In order for me to get back to that
record I click on their name again in the listbox and it shows that
employees
info.

If you remove the requery then the forms record position will not change.
It just not clear why you have the requery in your code anyway....

You might not even need the above sample code to force a disk write
either...
 
S

Secret Squirrel

Yes I do need to requery there, or at least something that will update that
record. One part I left out was once the link is created to the picture file
the picture is then shown in an image box on the form. The picture will not
appear unless a requery is done. Unless there is another way to requery the
form without moving to the first record.

Albert D. Kallal said:
Forms![frmEmployeeMain].Form.Requery


Do you need to do a requery here?

If you looking to force a disk write, simple go:

If me.Dirty = True then
me.Dirty = false
end if

The above will force the data to disk for you. I not really sure you need
the requery? (as that will force a complete re-load of the form and movement
to the first record...
In order for me to get back to that
record I click on their name again in the listbox and it shows that
employees
info.

If you remove the requery then the forms record position will not change.
It just not clear why you have the requery in your code anyway....

You might not even need the above sample code to force a disk write
either...
 
A

Albert D. Kallal

Secret Squirrel said:
Yes I do need to requery there, or at least something that will update
that
record.

Then give the sample code I gave. So, try:

if me.dirty = true then
me.dirty = false
end if

The above will force a disk write....

You can also use:

me.refresh

In place of the me.dirty code.
One part I left out was once the link is created to the picture file
the picture is then shown in an image box on the form. The picture will
not
appear unless a requery is done. Unless there is another way to requery
the
form without moving to the first record.

Try the disk write idea (s).

As a last resort, you could save the current record you are on, do a
requery..and then move the record back (but, I would exhaust the above
suggestions first).
 
T

Tom Wickerath

Hi Secret Squirrel,

What about setting the path to the image frame programmatically? Something
like this:

Private Sub ImagePath_AfterUpdate()
' After selecting an image for the employee, display it.
On Error Resume Next
'ShowErrorMessage
ShowImageFrame
If (IsRelative(Me.ImagePath) = True) Then
Me.ImageFrame.Picture = path & Me.ImagePath
Else
Me.ImageFrame.Picture = Me.ImagePath
End If
End Sub

Take a look at my ImageDemo sample for an example (currently requires Access
2002 or later):

http://www.accessmvp.com/TWickerath/downloads/ImageDemo.zip


Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top