Vba

unclefink

Registered User.
Local time
Today, 01:35
Joined
May 7, 2012
Messages
184
I am trying to learn some aspects of vba and based on reading some things and pure trial and error, I dont think i'm getting very far. I'm really jumping the gun as i have a class next month.

In any case, can anyone help me out with this. The intention for this is when i click a button on a form the message pops up and depending on the button chosen something happens.

If I click yes, macro runs, if i choose no, the window closes. Once I figure this part out, I will likely make the no button open a new message indicating command canceled or something to that afect.

In any case, can anyone direct me with the code problem?

Code:
Public Sub command9_click()
Dim answer As Byte, msg As String
answer = MsgBox(" Running this command will transfer all pending jobs whose dates have already passed to the main database table then delete them from Pending status, Is this what you want to do?", vbYesNo, "question")
If [vbYes] Then
DoCmd.RunMacro "macro1"
Else
End If
End Sub
 
You're not testing the variable. ;)
 
Your code should look like;
Code:
   Dim Answer As Byte
    Answer = MsgBox( "Running this command will transfer all pending jobs whose dates have already passed to the main database table then delete them from Pending status, Is this what you want to do?", vbYesNo, "question")
    
    If Answer = vbYes Then
          DoCmd.RunMacro "macro1"
    End If

Or alternately;
Code:
   If MsgBox("Running this command will transfer all pending jobs whose dates have already passed to the main database table then delete them from Pending status, Is this what you want to do?", vbYesNo, "question") = vbYes Then
        DoCmd.RunMacro "macro1"
    End If
 
Your code should look like;
Code:
   Dim Answer As Byte
    Answer = MsgBox( "Running this command will transfer all pending jobs whose dates have already passed to the main database table then delete them from Pending status, Is this what you want to do?", vbYesNo, "question")
 
    If Answer = vbYes Then
          DoCmd.RunMacro "macro1"
    End If

Or alternately;
Code:
   If MsgBox("Running this command will transfer all pending jobs whose dates have already passed to the main database table then delete them from Pending status, Is this what you want to do?", vbYesNo, "question") = vbYes Then
        DoCmd.RunMacro "macro1"
    End If

Thank you John.

So far this is all "study" material followed by trial and error and then trying to diagnose why it does what it does. How would i implement it further that if the no button is pushed it opens a new window indicating "process Canceled". Here is what I was thinking but it appears as though I am missing a process or the correct verbage in either case.

Code:
If MsgBox("Running this command will transfer all pending jobs whose dates have already passed to the main database table then delete them from Pending status, Is this what you want to do?", vbYesNo, "question") = vbYes Then
        DoCmd.RunMacro "macro1"
If MsgBox = vbno then
msg "Action Cancelled"
    End If
 
Thank you John.

So far this is all "study" material followed by trial and error and then trying to diagnose why it does what it does. How would i implement it further that if the no button is pushed it opens a new window indicating "process Canceled". Here is what I was thinking but it appears as though I am missing a process or the correct verbage in either case.

Code:
If MsgBox("Running this command will transfer all pending jobs whose dates have already passed to the main database table then delete them from Pending status, Is this what you want to do?", vbYesNo, "question") = vbYes Then
        DoCmd.RunMacro "macro1"
If MsgBox = vbno then
msg "Action Cancelled"
    End If

This code will not do what you want because Msgbox is a Function, and your second instance is not proper usage. The good news is that you do not need a second usage. Instead, Look up the If() statement and you will find two exception clauses (Else and ElseIf). In your case using an Else Clause will take you closer to what you are looking for. You should take time to read more details regarding If Statements on your own.
Code:
If MsgBox("Running this command will transfer all pending jobs whose dates have already passed to the main database table then delete them from Pending status, Is this what you want to do?", vbYesNo, "question") = vbYes Then
    DoCmd.RunMacro "macro1"
Else
    MsgBox "Action Cancelled"
End If
 

Users who are viewing this thread

Back
Top Bottom