473,411 Members | 1,998 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

Check to see if a button has been clicked on a form

Hi
Is there a property in MS Access for the following:
1) For a Command Button on a form, is there a property that can be used
to determine if it has been clicked?
eg: Me!button7.Clicked - I don't know if there is even a property like
that(Clicked)

2) For a Text Field on a form, is there a property that can be used to
find out if data has been entered in it?
I've tried Me!Textfield1.Value = Null but I'm not sure if that's the
right approach

Thanks

Nov 13 '05 #1
7 11691
#1...
just the "click" event... of the button... Why do you need to know if
it's been clicked? If you want, you can disable it after it's been
clicked... or create a static variable in your form that gets set to
true when you click the button... other than that, I don't think so.
VB doesn't "remember" these things unless you code for it.

#2
use the Dirty event of the control... then it'll flag if the user has
entered or changed anything in it.

Nov 13 '05 #2
There's a couple of buttons on the form that trigger different events.
"button1" adds records into a table, "button2" opens a new form based
on the newly entered record. If a user clicks on button2 before button1
has already been clicked, the new form will open with blank fields
since no data has been entered into the table. If you can think of a
better way of doing it, please let me know..Thanks

Nov 13 '05 #3
There isn't a property to indicate that a button has been clicked, but there
is an Event that will do this. You could then set a "flag" variable in the
button's Click event to remember that it had been previously clicked. The
flag would need to be Static in the procedure or Dim'ed with module level
scope or higher.

Null is the absence of a value. You can set something to Null with x = Null,
but you can't check to see if something is currently Null that way. To see
if something is null, try IsNull(Me!TextField1). This will return True or
False.

--
Wayne Morgan
MS Access MVP
"Shaldaman" <sh************@gmail.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
Hi
Is there a property in MS Access for the following:
1) For a Command Button on a form, is there a property that can be used
to determine if it has been clicked?
eg: Me!button7.Clicked - I don't know if there is even a property like
that(Clicked)

2) For a Text Field on a form, is there a property that can be used to
find out if data has been entered in it?
I've tried Me!Textfield1.Value = Null but I'm not sure if that's the
right approach

Thanks

Nov 13 '05 #4
Thanks a lot, Wayne. Using the IsNull(Me!TextField1) approach solved
my problem.

Nov 13 '05 #5

Shaldaman wrote:
There's a couple of buttons on the form that trigger different events.
"button1" adds records into a table, "button2" opens a new form based
on the newly entered record. If a user clicks on button2 before button1
has already been clicked, the new form will open with blank fields
since no data has been entered into the table. If you can think of a
better way of doing it, please let me know..Thanks


Do you want the Form to Not open if no records are present?

To check if button1 was clicked put a checkbox on your main form. When
button1 is clicked, use the afterupdate event of button1 to set the
checkbox value to true. Then, in the onclick event of button2 check if
the checkbox is true (set), if true then open form if false use a
message box or cancel the open form event.

osmethod

Nov 13 '05 #6
Shaldaman wrote:
There's a couple of buttons on the form that trigger different events.
"button1" adds records into a table, "button2" opens a new form based
on the newly entered record. If a user clicks on button2 before button1
has already been clicked, the new form will open with blank fields
since no data has been entered into the table. If you can think of a
better way of doing it, please let me know..Thanks


Osmethod has suggested one viable way of doing this that is form level.
I'd prefer to do this the following way.

In the second form, the one that opens, in the on open event put in the
following code, near the top of your code, if you already have code
there for the on open event (watch for wrap):

Private Sub Form_Open(Cancel As Integer)

If Me.RecordsetClone.EOF Then

msgbox "You haven't added any records yet!", vbexclamation, "You Need
to Click Button1, first!"

Cancel = True

end if

End Sub

If you already have other code, do it this way:
Private Sub Form_Open(Cancel As Integer)

If Me.RecordsetClone.EOF Then

msgbox "You haven't added any records yet!", vbexclamation, "You Need
to Click Button1, first!"

Cancel = True

else

<do other code>

end if

End Sub

That's not all, just the above will raise an error with button2 if
button2 does not have error trapping.

Button2 should look something like:

Private Sub Button2_Click()

On Error GoTo Err_Proc

DoCmd.OpenForm "The FormThatOpensTheTableName"

Exit_Proc:

Exit Sub

Err_Proc:

Select case err.number

Case 2501 'DoCmd cancelled - form had no records

Resume Exit_Proc

Case Else

MsgBox "Error " & Err.Number & " " & Err.Description,
vbCritical, "Error Button2_Click", Err.HelpFile, Err.HelpContext

Resume Exit_Proc

End Select

End Sub
--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Whatcha doin?" - Ditto "TIM-MAY!!" - Me
Nov 13 '05 #7
I just wanted to say thanks to everyone for helping out. I really
appreciate it. Thanks.

Tim Marshall wrote:
Shaldaman wrote:
There's a couple of buttons on the form that trigger different events.
"button1" adds records into a table, "button2" opens a new form based
on the newly entered record. If a user clicks on button2 before button1
has already been clicked, the new form will open with blank fields
since no data has been entered into the table. If you can think of a
better way of doing it, please let me know..Thanks


Osmethod has suggested one viable way of doing this that is form level.
I'd prefer to do this the following way.

In the second form, the one that opens, in the on open event put in the
following code, near the top of your code, if you already have code
there for the on open event (watch for wrap):

Private Sub Form_Open(Cancel As Integer)

If Me.RecordsetClone.EOF Then

msgbox "You haven't added any records yet!", vbexclamation, "You Need
to Click Button1, first!"

Cancel = True

end if

End Sub

If you already have other code, do it this way:
Private Sub Form_Open(Cancel As Integer)

If Me.RecordsetClone.EOF Then

msgbox "You haven't added any records yet!", vbexclamation, "You Need
to Click Button1, first!"

Cancel = True

else

<do other code>

end if

End Sub

That's not all, just the above will raise an error with button2 if
button2 does not have error trapping.

Button2 should look something like:

Private Sub Button2_Click()

On Error GoTo Err_Proc

DoCmd.OpenForm "The FormThatOpensTheTableName"

Exit_Proc:

Exit Sub

Err_Proc:

Select case err.number

Case 2501 'DoCmd cancelled - form had no records

Resume Exit_Proc

Case Else

MsgBox "Error " & Err.Number & " " & Err.Description,
vbCritical, "Error Button2_Click", Err.HelpFile, Err.HelpContext

Resume Exit_Proc

End Select

End Sub
--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Whatcha doin?" - Ditto "TIM-MAY!!" - Me


Nov 13 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Deepiceman | last post by:
Hi all, I am new to asp so bear with me. I want to write a page which will load a default page for me with some links and all. lets say someone clicks on the link, which not only points to the...
4
by: Jared | last post by:
Radio Button or Check Box and Event Procedures I need to insert either radio buttons or check boxes onto my form. I'm not sure which to use, or if there are other options. I am using the buttons...
2
by: Travis.Box | last post by:
I have an MS Access userform with 16 Check Boxes. Each of the checkboxes has a different option value, which coincides with the Check Box name (eg. cb01.OptionValue = 1). At the bottom of the...
4
by: Neil Coleclough | last post by:
I am constructing a database to process product returns for my Company. I have a number of toggle buttons to identify the stage to which each return has been processed. For example, clicking the...
2
by: Krista Lemieux | last post by:
Hello, In my form I have a button, and the button_Click function (which gets called when the button is clicked). However the functionality that I have in the button_Click function, needs to be...
4
by: Shawn | last post by:
Hi. I have a ToolBar with a couple of ToolBarButtons. On postback after clicking on of the buttons Page_Load is called first then the ToolBarButton's click event is called. Is there anyway for...
1
by: JHawk24821 | last post by:
I am building a simple card matching game where the user picks two buttons on a form out of a group of buttons in an attempt to find a match. I have already taken care of the randomization needed...
5
by: sumeetmakkar | last post by:
Hi all, I am a begineer and working on a project. Facing trouble linking a submit buuton to a page of my choice.Script i am using is: <SCRIPT language=JavaScript><!-- function validate(form) {...
0
by: Tony | last post by:
I am continuing to develop an Access 2007 application which was originally converted from Access 2003. In Access 2003 I was able to disable the Access Close button in the top righthand corner of...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.