Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Command Button on Form

Status
Not open for further replies.

3063

Technical User
Jan 17, 2003
63
US
I have working on an employee database and have received a lot of help from this website, but still need some assistance. I have a form that shows a record of each employee's picture and info about them. I have button that I need to show up in the "last record." The code works that I received, except that it shows up in an empty record. I tried going into the properties of the form and making it where you could not add or edit records so it would not go to the next record where it is blank record. (I need this to be a read only form.) Once I made those changes, the button would not appear. Here's the code: If Me.NewRecord Then
Me.cmdPicture.Visible = True
Else
Me.cmdPicture.Visible = False
End If
End Sub
 
NewRecord" is where you are when you move past the last record in the recordset. Because you are now preventing it from doing that you never get Me.NewRecord evaluating to True so the button never appears.

You might try something like
Code:
With Me.Recordset
   If .AbsolutePosition + 1 = .RecordCount Then
       Me.cmdPicture.Visible = True
   Else
       Me.cmdPicture.Visible = False
   End If
End With


[small]No! No! You're not thinking ... you're only being logical.
- Neils Bohr[/small]
 
When I created a new form and took out the code I need in the On Current of the form to display the linked pictures, it worked. Is there a way I can have two different sets of code in the On Current of the form? This what I have in the OnCurrent to display my linked pictures:

Private Sub Form_Current()
On Error GoTo Err_cmdClose_Click

'set the picture path
Me.ImgStock.Picture = Me.ImagePath

Exit_cmdClose_Click:
Exit Sub

Err_cmdClose_Click:
If Err.Number = 2220 Then 'can't find the file
Resume Next
ElseIf Err.Number = 94 Then 'invalid use of null
Me.ImgStock.Picture = ""
Resume Next
Else
MsgBox Err.Description
Resume Exit_cmdClose_Click
End If
End Sub
 
Ok..It worked when I first created the form, but once I got out of the form and came back into the form, the button shows up for all the records.
 
In the Form_Activate event
Code:
Me.cmdPicture.Visible = False

[small]No! No! You're not thinking ... you're only being logical.
- Neils Bohr[/small]
 
It still does not work. Once you close down the form and reopen it the button is visible again.
 
Perhaps this ?
Private Sub Form_Current()
On Error GoTo Err_cmdClose_Click
'set the picture path
Me.ImgStock.Picture = Me.ImagePath
[!] Me.cmdPicture.Visible = (Me.Recordset.AbsolutePosition + 1 = Me.Recordset.RecordCount)[/!]
Exit_cmdClose_Click:
Exit Sub
...

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
How are ya 3063 . . .

Code [blue]to be provided[/blue] depends on wether the form is set for [blue]Single or Continiuous view[/blue]? . . .

. . . and your answer is?

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top