command buttons

  • Thread starter Ozzie via AccessMonster.com
  • 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
 
A

Allen Browne

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
 
O

Ozzie via AccessMonster.com

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.
 
A

Allen Browne

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.
 
O

Ozzie via AccessMonster.com

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]
 
A

Allen Browne

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.
 
O

Ozzie via AccessMonster.com

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]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top