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!

Hide Button 2

Status
Not open for further replies.

daniels012

Technical User
Jan 19, 2005
55
US
I want to hide a button on my form when the record is new. How can I add this to my code of the button??

Here is the code now:
Private Sub Command876_Click()
DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdCopy
DoCmd.RunCommand acCmdPasteAppend
End Sub

This copies data from one record onto a new blank form. Obviously I don't want to copy blank info into a new form.

Any help would be greatly appreciated!
Michael
 

if not me.newrecord then
DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdCopy
DoCmd.RunCommand acCmdPasteAppend
end if

 
I have this code on the "On Click" Event
Where should I put
Command876.Visible=False
in my code?

If I use this code, does this hide my button?
if not me.newrecord then
DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdCopy
DoCmd.RunCommand acCmdPasteAppend
end if

Thank You,
Michael
 
Also can I go to a specific control and clear the control on my new page with all the data?
example: I would like to go to control "SampleNumber" while clearing the data it has?

Thank You,
Michael
 
How are ya daniels012 . . . . .

Microsoft said:
[blue]You can't hide a control while it has the focus . . .[/blue]

So . . . try this:
Code:
[blue]If Not Me.NewRecord Then
   Me!SampleNumber.SetFocus
   DoCmd.RunCommand acCmdSelectRecord
   DoCmd.RunCommand acCmdCopy
   DoCmd.RunCommand acCmdPasteAppend
   Me!SampleNumber = ""
   Me!Command876.Visible = False
End If[/blue]

Calvin.gif
See Ya! . . . . . .
 
Hello TheAceMan1,
I think this will work fine. Where do I put it?? Maybe, in my buttons properties "On Click" or on the Forms properties? Because I only want to copy the data when the button is hit, but I only want the button to show when the form has data, so that data can go to the next record?

Sorry, I'm kinda green to access coding!

Thank You,
Michael
 
daniels012 . . . .

Replaces your origional code in [blue]Private Sub Command876_Click()[/blue]

Calvin.gif
See Ya! . . . . . .
 
I had it on the "On Click" properties. Now it only Visible or not when I click??
Is there a way I can, say for example I have a text box called Company, If Company is empty or Null then my "CopySample"(used to be Command876) button would not appear. This way I know when there is a new record, there is no data in the Company field and my button would not appear.
 
How about....

In your form's OnCurrent event, place this code:

If IsNull(me.txtCompany) Or me.txtCompany = "" Then
me.cmdCopySample.Visible = False
Else
me.cmdCopySample.Visible = True
End If



Randy
 
OK daniels012 . . . . .

In the forms [blue]Current Event[/blue] & [blue]AfterUpdate Event[/blue] of [blue]Company[/blue], copy/paste the following line:
Code:
[blue]   Call visCompany[/blue]
Then in the code module for the form, copy/paste the following routine:
Code:
[blue]Public Sub visCompany()
   If Trim(Me!Company & "") = "" Then
      me.cmdCopySample.Visible = False
   Else
      me.cmdCopySample.Visible = True
   End If
End Sub[/blue]

Calvin.gif
See Ya! . . . . . .
 
Andy700 and TheAceMan1,
Thank You very much!!
These both worked!
I am fairly new to doing code so this really helped!

Thanks again,
Michael
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top