Hello All,
i want to program a button , this button can be pressed one time and add ( save records to a table ).
this will be used for distribution items to make sure duplicates not happens
regards
program a button that can be clicked one time?
-
- BronzeLounger
- Posts: 1227
- Joined: 01 May 2016, 09:58
-
- Administrator
- Posts: 78488
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: program a button that can be clicked one time?
Set the Visible property of the command button to No.
Create a table tblSettings with a single field ButtonVisible of type Yes/No.
Save the table, then open it and tick the check box, then close the table.
Create an On Load event procedure for the form:
where cmdAdd is the name of the button.
In the On Click event of cmdAdd:
Initially, the On Load event procedure of the form will make the button visible, since the value of ButtonVisible is true. But once the button has been clicked, it will be hidden.
Create a table tblSettings with a single field ButtonVisible of type Yes/No.
Save the table, then open it and tick the check box, then close the table.
Create an On Load event procedure for the form:
Code: Select all
Private Sub Form_Load()
Me.cmdAdd.Visible = DLookup("ButtonVisible", "tblSettings")
End Sub
In the On Click event of cmdAdd:
Code: Select all
Private Sub cmdAdd_Click()
' Your code to add records goes here
' ...
' Set the ButtonVisible field in tblSettings to False for next time
CurrentDb.Execute "UPDATE tblSettings SET ButtonVisible = False", dbFailOnError
' Set focus to another control
Me.SomeOtherControl.SetFocus
' Hide the command button
Me.cmdAdd.Visible = False
End Sub
Best wishes,
Hans
Hans
-
- BronzeLounger
- Posts: 1227
- Joined: 01 May 2016, 09:58
Re: program a button that can be clicked one time?
that's working fine, but I wanted to make it more complicated.
i have a tblDist_items with one to many relationships with tblBenefciareis , so what i did instead of creating a single table I added a new field to the tblDist_items
and now i want this button enabled or visible for those row which is status is assessed or not received,
so based on the row the status of the button will be changed ... my be im doing this in the wrong way if you suggest another way will be great....
in summery the button Change status will have three function
1- inject date to Recived date
2- change the status of the status combo box to received
3- disabled itself for received items...
i have a tblDist_items with one to many relationships with tblBenefciareis , so what i did instead of creating a single table I added a new field to the tblDist_items
and now i want this button enabled or visible for those row which is status is assessed or not received,
so based on the row the status of the button will be changed ... my be im doing this in the wrong way if you suggest another way will be great....
in summery the button Change status will have three function
1- inject date to Recived date
2- change the status of the status combo box to received
3- disabled itself for received items...
You do not have the required permissions to view the files attached to this post.
-
- Administrator
- Posts: 78488
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: program a button that can be clicked one time?
You don't need to enable/disable the button, since it applies to multiple records in the subform. You specify a from date and to date, and the code will change the status for ALL records whose AssessedDate falls within the date range.
Best wishes,
Hans
Hans
-
- BronzeLounger
- Posts: 1227
- Joined: 01 May 2016, 09:58
Re: program a button that can be clicked one time?
thank you for the reply
actually, I need the enable/disable functionality, in order to enable the user not able to click the button if the item already received.
i got another idea , if i create a nother form that filter data acording the date from and date to , and put the button chage status on this form ... it should change the enable property to false only to filtered rows ... does this a good way or tehre is a better way?
regards
actually, I need the enable/disable functionality, in order to enable the user not able to click the button if the item already received.
i got another idea , if i create a nother form that filter data acording the date from and date to , and put the button chage status on this form ... it should change the enable property to false only to filtered rows ... does this a good way or tehre is a better way?
regards
-
- Administrator
- Posts: 78488
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: program a button that can be clicked one time?
Again, there is NO need to enable/disable the button, or to filter the form.
Change the line that specifies the SQL to
With the addition "... AND Status=1", the code will only be applied to records whose status is Assessed.
Change the line that specifies the SQL to
Code: Select all
strSQL = "UPDATE tblDist_items SET DateReceived=#" & Format(Me.txtNewDate, "yyyy/mm/dd") & "#, Status=" & lngStatus & _
" WHERE BenefID_FK=" & Me.BenefID & " AND AssessedDate Between #" & _
Format(Me.txtDateFrom, "yyyy/mm/dd") & "# And #" & Format(Me.txtDateTo, "yyyy/mm/dd") & "# AND Status=1"
Best wishes,
Hans
Hans
-
- BronzeLounger
- Posts: 1227
- Joined: 01 May 2016, 09:58
Re: program a button that can be clicked one time?
thanks, Hans, I know its apply to the fields where the status is 1, but let me explain what is in my head maybe you will come back with another idea ...
when someone is asking for items .. we find him and apply the change of the status ... if the same person comes back again and ask for his item ... we woud like to have a fast indication that he already received his items... it sound silly because i know the status has been changed to receive but when you are in crowd and surrounded by hundreds of people you need a fast way to find out, if you think this is enough then that is it..
when someone is asking for items .. we find him and apply the change of the status ... if the same person comes back again and ask for his item ... we woud like to have a fast indication that he already received his items... it sound silly because i know the status has been changed to receive but when you are in crowd and surrounded by hundreds of people you need a fast way to find out, if you think this is enough then that is it..
-
- Administrator
- Posts: 78488
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: program a button that can be clicked one time?
I think this is not necessary. If you feel it is, you'll have to work out the code for yourself.
Best wishes,
Hans
Hans
-
- BronzeLounger
- Posts: 1227
- Joined: 01 May 2016, 09:58
Re: program a button that can be clicked one time?
Thank you Hans for your quick prompt...
so i will leave it as it
thanks again , you helped me a lot
so i will leave it as it
thanks again , you helped me a lot