command buttons

  • Thread starter Thread starter Ozzie via AccessMonster.com
  • Start date Start date
O

Ozzie via AccessMonster.com

Hi Guys,

I have a command button, placed on a form, that when it is clicked performs a
function.

What I need to be able to do is;

when the button has been "clicked" to change the message on the button to
read "your current period has been set to" & the max date field in a table
called current period.

any body have any ideas?

anything appreciated,

many thanks

David
 
Use DMax() to get the date value from the table, e.g.:

Private Sub ClickMe_Click()
Me.[ClickMe].Caption = "your current period has been set to " &
DMax("[YourDateField]", "[current period]")
End Sub
 
Allen,

Cheers for the speedy resonse, however I think i'm applying it in the wrong
place?

on the command button i have the following code on the "on click" option;

Private Sub Command48_Click()
On Error GoTo Err_Command48_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "F_CurrentPeriod"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command48_Click:
Exit Sub

Err_Command48_Click:
MsgBox Err.Description
Resume Exit_Command48_Click
End Sub


the user then updates the current period and closes the form, to return to
the starting point, then your code;

Private Sub ClickMe_Click()
Me.[ClickMe].Caption = "Your current period has been set to " & DMax("
[T_CurrentPeriod]", "[CurrentMonth]")
End Sub

however he text on the command button hasn't changed?







Allen said:
Use DMax() to get the date value from the table, e.g.:

Private Sub ClickMe_Click()
Me.[ClickMe].Caption = "your current period has been set to " &
DMax("[YourDateField]", "[current period]")
End Sub
I have a command button, placed on a form, that when it is clicked
performs a
[quoted text clipped - 5 lines]
read "your current period has been set to" & the max date field in a table
called current period.
 
If you want the button's Caption to be set only after the F_CurrentPeriod
form closes, you will need to open it in dialog mode:

Private Sub Command48_Click()
On Error GoTo Err_Command48_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "F_CurrentPeriod"
DoCmd.OpenForm stDocName, , , stLinkCriteria, ,acDialog
Me.Command48.Caption = "Your current period has been set to " & _
DMax("[T_CurrentPeriod]", "[CurrentMonth]")

Exit_Command48_Click:
Exit Sub

Err_Command48_Click:
MsgBox Err.Description
Resume Exit_Command48_Click
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Ozzie via AccessMonster.com said:
Allen,

Cheers for the speedy resonse, however I think i'm applying it in the
wrong
place?

on the command button i have the following code on the "on click" option;

Private Sub Command48_Click()
On Error GoTo Err_Command48_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "F_CurrentPeriod"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command48_Click:
Exit Sub

Err_Command48_Click:
MsgBox Err.Description
Resume Exit_Command48_Click
End Sub


the user then updates the current period and closes the form, to return to
the starting point, then your code;

Private Sub ClickMe_Click()
Me.[ClickMe].Caption = "Your current period has been set to " &
DMax("
[T_CurrentPeriod]", "[CurrentMonth]")
End Sub

however he text on the command button hasn't changed?


Allen said:
Use DMax() to get the date value from the table, e.g.:

Private Sub ClickMe_Click()
Me.[ClickMe].Caption = "your current period has been set to " &
DMax("[YourDateField]", "[current period]")
End Sub
I have a command button, placed on a form, that when it is clicked
performs a
[quoted text clipped - 5 lines]
read "your current period has been set to" & the max date field in a
table
called current period.
 
Allen,

Thanks for the reply, I have used the code as instructed, and the button
caption now update, however it doesn't pick up the latest date?, the DMAX
doesn't seem to work?

Cheers for you help,

David

Allen said:
If you want the button's Caption to be set only after the F_CurrentPeriod
form closes, you will need to open it in dialog mode:

Private Sub Command48_Click()
On Error GoTo Err_Command48_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "F_CurrentPeriod"
DoCmd.OpenForm stDocName, , , stLinkCriteria, ,acDialog
Me.Command48.Caption = "Your current period has been set to " & _
DMax("[T_CurrentPeriod]", "[CurrentMonth]")

Exit_Command48_Click:
Exit Sub

Err_Command48_Click:
MsgBox Err.Description
Resume Exit_Command48_Click
End Sub
[quoted text clipped - 45 lines]
 
Use the Debug window (Ctrl+G) to trace down what's going on.

Enter:
? DMax("[T_CurrentPeriod]", "[CurrentMonth]")

Trace through the name of the field, the name of the table, the data type,
and so on, until you track it down.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Ozzie via AccessMonster.com said:
Allen,

Thanks for the reply, I have used the code as instructed, and the button
caption now update, however it doesn't pick up the latest date?, the DMAX
doesn't seem to work?

Cheers for you help,

David

Allen said:
If you want the button's Caption to be set only after the F_CurrentPeriod
form closes, you will need to open it in dialog mode:

Private Sub Command48_Click()
On Error GoTo Err_Command48_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "F_CurrentPeriod"
DoCmd.OpenForm stDocName, , , stLinkCriteria, ,acDialog
Me.Command48.Caption = "Your current period has been set to " & _
DMax("[T_CurrentPeriod]", "[CurrentMonth]")

Exit_Command48_Click:
Exit Sub

Err_Command48_Click:
MsgBox Err.Description
Resume Exit_Command48_Click
End Sub
[quoted text clipped - 45 lines]
table
called current period.
 
Thanks, Allen,

I have now sorted it, in the end I had to add a line to delete all rows from
the table first then use the form to update the current period, doing this
makes the text on the command button correct every time.

thanks for all your help

David

Allen said:
Use the Debug window (Ctrl+G) to trace down what's going on.

Enter:
? DMax("[T_CurrentPeriod]", "[CurrentMonth]")

Trace through the name of the field, the name of the table, the data type,
and so on, until you track it down.
[quoted text clipped - 33 lines]
 
Back
Top