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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can you change the label of a VBYesNO command button? 2

Status
Not open for further replies.

testkitt2

Technical User
Apr 28, 2004
193
US
Hello to all...

I have a DB where I'm using a VBYesNO command and I want to change its label from Yes..NO... to something like Dept600 and Dept650 respectfully.. Is there anyway to do this ?

Any help or suggestions are appreciated.

Thank you
JZ

Testkitt2
 
Hi
Do you mean a message box? If so, I do not think so, but you can build your own message boxes with any labels you fancy.
 
Thanks Remou for your response..

and yes I mean a msgbox...

The YesNO command is attached to a msgbox where the user
picks from.

Can't be done...huh...
How would I go about building my own msg?
can you post a small example?

Thank you
JZ

Testkitt2
 
All you need is a small form. Here is a little code that set various properties for a suitable form:
Code:
Sub FormatDialog(frmname As String)
Dim frm As Form
Dim prp As Property
DoCmd.OpenForm frmname, acDesign, , , , acHidden
Set frm = Forms(frmname)
With frm
    .AllowDesignChanges = False
    .AutoCenter = True
    .AutoResize = False
    .BorderStyle = 3 'Dialog
    .ControlBox = False
    .DefaultView = 0 'single form
    .DividingLines = False
    .Modal = True
    .NavigationButtons = False
    .ScrollBars = 0 'none
    .RecordSelectors = False
    .ViewsAllowed = 1 'form
    '.WindowHeight = 5310
    '.WindowWidth = 10755
End With
Set frm = Nothing
DoCmd.Close acForm, frmname, acSaveYes
End Sub

You can then add a label and a few control buttons. The label caption property can be changed programatically to suit to suit your requirements. When you are using the form, you will need to open it with:
[tt]DoCmd.OpenForm "CustomMsg", , , , , acDialog[/tt]
You can refine the whole thing with openargs and such like.
 
Thanks Remou,

I'll give it a try ...and post results.

Thanks again
JZ

Testkitt2
 
Thanks Remou,

I'm sorry for being confused.... but where would I insert the code? or do I set the properties of a form with these settings?

Thank you
JZ

Testkitt2
 
Remou's suggestions are very helpful and insightful.
alternatively, you can set those same properties in the Properties dialog box, in design view of the form. I assume, as you are aware.

As far as the checkbox controls are concerened, is it one control that when checked, the label changes, or 2 controls each with their respective label?

If the former is true...

Private Sub chkDept_Click()
lblDept.Caption = IIF(chkDept, "Dept600", "Dept650")
End Sub

otherwise all can be done from Form design view, no need to code, except for your main objective, of course.
 

And the code below is from AllAPI.net that is altered a little to use with VB6 and works with Access too. I can't find either post in VB6 forum or the page at AllAPI.net
So the credit goes to them
Code:
Option Compare Database
Option Explicit
Const MB_DEFBUTTON1 = &H0&
Const MB_DEFBUTTON2 = &H100&
Const MB_DEFBUTTON3 = &H200&
Const MB_ICONASTERISK = &H40&
Const MB_ICONEXCLAMATION = &H30&
Const MB_ICONHAND = &H10&
Const MB_ICONINFORMATION = MB_ICONASTERISK
Const MB_ICONQUESTION = &H20&
Const MB_ICONSTOP = MB_ICONHAND
Const MB_OK = &H0&
Const MB_OKCANCEL = &H1&
Const MB_YESNO = &H4&
Const MB_YESNOCANCEL = &H3&
Const MB_ABORTRETRYIGNORE = &H2&
Const MB_RETRYCANCEL = &H5&
Private Declare Function MessageBox Lib "user32" Alias "MessageBoxA" (ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long) As Long


Private Sub Form_Load()
    MessageBox Me.hwnd, "My message", CurrentProject.Name, MB_YESNOCANCEL
    MessageBox Me.hwnd, "My message", "My custom title", MB_ABORTRETRYIGNORE
    End
End Sub

<[URL unfurl="true"]http://www.allapi.net/>[/URL]  Altered a little

________________________________________________________
Zameer Abdulla
Help to find Missing people
You may be the boss' pet; but you are still an animal
 
ZmrAbdulla
You seem to find the most useful stuff! Thanks for this.
 
Remou, Thanks for the
star.gif


________________________________________________________
Zameer Abdulla
Help to find Missing people
You may be the boss' pet; but you are still an animal
 
Hey thanks to all that replied.

Ok to clarify myself a bit..what I was talking about was the msgbox that access has built in.
like lets says you have an if statement....
Code:
dim answer as integer
answer = msgbox (" My msg ",VBQuestion+VBYesNO,"DBAdmin")
if anwer = vbNo then
exit sub
else
docmd.openform.........
endif
end sub

In the VBYesNO in the msg above...my original question was..
change I change the Yes...No... to something else..with out
creating a Command button.

Thanks again
JZ


Testkitt2
 
Default messagebox's style provided by Access/VBA can't be changed easily. This is the reason programmers use their own expertise to create messagebox.
If you are not able to use the code that I suggested then try Remou's. It is very easy. If you add "OpenArgs" to that then you could use the same for many instances with different title and action.

________________________________________________________
Zameer Abdulla
Help to find Missing people
You may be the boss' pet; but you are still an animal
 
Thanks to all for your input.

I tried the code and it works as ZmrAbdulla
suggested...my question is this..look at the code below can MB_YESNOCANCEL be changed
to something else entirely different... like MB_DEPT600DEPT650 ? (DEPT600 Being on one button and DEPT650 being on another).
Code:
Private Sub Form_Load()
    MessageBox Me.hwnd, "My message", CurrentProject.Name, MB_YESNOCANCEL
    MessageBox Me.hwnd, "My message", "My custom title", MB_ABORTRETRYIGNORE
    End
End Sub

**************
Maybe my whole approach is wrong..
This is what I have now..
I have a command button that when the user clicks on it, a msg comes up to click yes for form Dept600 to appear and click No for form Dept650 to appear and cancel to cancel.
I want the Yes / No to say Dept600 and Dept650 respectively.

Thanks again
JZ


Testkitt2
 
I may be wrong.. I am writing as per my understanding of the question. Forget about the code given earlier and try the code below
Code:
Private Sub Command1_Click()
    Dim Msg, Style, Title, Help, Ctxt, Response, MyString
    Msg = "click yes for form Dept600 to appear and " & _
          "click No for form Dept650 to appear"
    ' Define message.
    Style = vbYesNoCancel + vbInformation
    Title = "Choose Your file"    ' Define title.
    Response = MsgBox(Msg, Style, Title, Help, Ctxt)
    If Response = vbYes Then  
        MyString = "Yes"
        DoCmd.OpenForm "Dept600"
    Else
     If Response = vbNo Then
  MyString = "No"
        DoCmd.OpenForm "Dept650"
    Else
       'do nothing
End If
    End If
End Sub

________________________________________________________
Zameer Abdulla
Help to find Missing people
You may be the boss' pet; but you are still an animal
 
I was just playing with forms to create custom messageboxes.. Uploaded a sample on my site. may be interesting to you.
it is a 17kb zip file (132 kb access 2000 file)

________________________________________________________
Zameer Abdulla
Help to find Missing people
You may be the boss' pet; but you are still an animal
 
This a great thread, and I would mention my own thanks to all who contributed, but based on testkitt2's last reply I'd say you can simply put the two dept. command buttons in the first form to begin with, or have the original command button open a very simple modal form with two buttons or clickable labels. The goal as you expressed it is really very simple.
 
Thanks ZmrAbdulla;
Your code does exactly what I already have in my DB..
Your might be more efficient but does the same thing.

Ok when you click the command button the msgbox appears with the YESNOCANCEL option. I want to change the YESNOCANCEL TO DEPT600DEPT650CANCEL... This is probably not possible...uhh.

here's your code with a little alteration.
Code:
On Error GoTo Err_CmdExport_Click

    Dim stDocName600 As String
    Dim stDocNameCont As String
    Dim stLinkCriteria As String
    Dim answer As Integer
     stDocName600 = "SpendingView600"
    stDocNameCont = "SpendingViewCont"

Dim Msg, Style, Title, Help, Ctxt, Response, MyString
    Msg = "click yes for form Dept600 to appear and " & _
          "click No for form Dept650 to appear"
    ' Define message.
    Style = vbYesNoCancel + vbInformation
    Title = "Choose Your file"    ' Define title.
    Response = MsgBox(Msg, Style, Title, Help, Ctxt)
    If Response = vbYes Then
        MyString = "Yes"
        DoCmd.OpenForm stDocName600, , , stLinkCriteria
    Else
     If Response = vbNo Then
  MyString = "No"
        DoCmd.OpenForm stDocNameCont, , , stLinkCriteria
    Else
       'do nothing
End If
    End If


Exit_CmdExport_Click:
    Exit Sub

Err_CmdExport_Click:
    MsgBox Err.Description
    Resume Exit_CmdExport_Click
End Sub

Thanks again
JZ

Testkitt2
 
Here is the actual page of the code in allapi.net.
This provides a combination of buttons that vb/vba provides.
for your purpose you need to use the first one
paste the first part into a module and save it by any name

change the part
Code:
     'the ID's of the buttons on the message box
     'correspond exactly to the values they return,
     'so the same values can be used to identify
     'specific buttons in a SetDlgItemText call.
      SetDlgItemText wParam, IDABORT, [b]"Dept 600"[/b]
      SetDlgItemText wParam, IDRETRY, [b]"Dept 650"[/b]
      SetDlgItemText wParam, IDIGNORE, "Cancel"
      
     'Change the dialog prompt text ...
      SetDlgItemText wParam, IDPROMPT,[b] "Select the form you want to view"[/b]

and behind the click event of the command button on the form from where you are calling the message box place the code below.
Code:
   Select Case MessageBoxH(Me.hwnd, GetDesktopWindow())
      Case IDABORT: DoCmd.OpenForm "SpendingView600"
      Case IDRETRY: DoCmd.OpenForm "SpendingViewCont"
      Case IDIGNORE:
   End Select

hope this helps

________________________________________________________
Zameer Abdulla
Help to find Missing people
You may be the boss' pet; but you are still an animal
 

I copy this code into a new module and named it 'AlertUser'.
But when compling to check for errors it returned
This 'wParam' invalid outside procedure.

Code:
'the ID's of the buttons on the message box
     'correspond exactly to the values they return,
     'so the same values can be used to identify
     'specific buttons in a SetDlgItemText call.
      SetDlgItemText wParam, IDABORT, "Dept 600"
      SetDlgItemText wParam, IDRETRY, "Dept 650"
      SetDlgItemText wParam, IDIGNORE, "Cancel"
      
     'Change the dialog prompt text ...
      SetDlgItemText wParam, IDPROMPT, "Select the form you want to view"
Thanks..
JZ

Testkitt2
 
I said to paste the entire code from that site where it says paste into a module. Then the bold part of the code to be changed to fit your requirements. You can't abstract some from that.

________________________________________________________
Zameer Abdulla
Help to find Missing people
You may be the boss' pet; but you are still an animal
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top