+ Reply to Thread
Results 1 to 7 of 7

Add vbyes no code

  1. #1
    Forum Contributor
    Join Date
    12-21-2013
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    387

    Add vbyes no code

    Hi,
    I have a following code in my workbook
    i want to add vbyesno code with

    If rngFound Is Nothing Then
    MsgBox "ID not Found, Want to Create?" vbyesno



    PHP Code: 
    Private Sub cmdfndnext_Click()
        
    Dim strPrefix As StringstrSuffix As StringstrID As String
        Dim rngFound 
    As Rangerngstart As Range
        Dim i 
    As Long
        
        strID 
    Trim(txtid.Text)
        
        If 
    cmdfndnext.Tag "Next" Then
            Rem incriment ID number
            
    For Len(strIDTo 1 Step -1
                
    If Mid(strIDi1Like "[!0-9]" Then
                    strPrefix 
    Left(strIDi)
                    
    strSuffix Mid(strID1)
                    If 
    Len(strIDThen
                        strSuffix 
    Format(Val(strSuffix) + 1String(Len(strSuffix), "0"))
                    
    End If
                   Exit For
                
    End If
            
    Next i
            strID 
    strPrefix strSuffix
            txtid
    .Text strID
            
        End 
    If
        
        
    With Sheets("Life Member").Range("A:A")
            
    On Error Resume Next
            Set rngFound 
    = .Find(txtid.TextAfter:=.Cells(Rows.Count1), Lookat:=xlWholeLookIn:=xlValuesMatchCase:=True)
            
    On Error GoTo 0
        End With
        
        
    If rngFound Is Nothing Then
            MsgBox 
    "ID not Found"
            
        
    Else
            
    With rngFound.EntireRow
                            
                txtname
    .Text = .Cells(12).Text
                txtremark
    .Text = .Cells(13).Text
                txtstatus
    .Text = .Cells(14).Text
                txtreceipt
    .Text = .Cells(15).Text
                txtyear
    .Text = .Cells(16).Text
                

            End With
        End 
    If
        
        
    cmdfndnext.Tag "Next"
    End Sub 
    My English is very poor, so please be patient >_<"

    Thanks & Regards.
    hkbhansali

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Add vbyes no code

    There is no point in adding vbYesNo unless you also capture the user's response.

    Please Login or Register  to view this content.
    Now you need to specify what you want to do if the user answers Yes, and what if they answer No.

    Response will have the value vbYes or vbNo.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Forum Contributor
    Join Date
    12-21-2013
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    387

    Re: Add vbyes no code

    Hi, 6StringJazzer,

    I dont know how to coding your code.
    can u do this
    my answer is :

    if rngFound Is Nothing Then
    MsgBox "ID not Found, Want to create?" - vb yes

    and vb no
    Else
    With rngFound.EntireRow

    txtname.Text = .Cells(1, 2).Text
    txtremark.Text = .Cells(1, 3).Text
    txtstatus.Text = .Cells(1, 4).Text
    txtreceipt.Text = .Cells(1, 5).Text
    txtyear.Text = .Cells(1, 6).Text

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Add vbyes no code

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)

  5. #5
    Forum Contributor
    Join Date
    12-21-2013
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    387

    Re: Add vbyes no code

    SORRY FOR BROKEN FOURM RULES..

    here i submit new post:

    PHP Code: 
    Private Sub cmdfndnext_Click()
        
    Dim strPrefix As StringstrSuffix As StringstrID As String
        Dim rngFound 
    As Rangerngstart As Range
        Dim i 
    As Long
        
        strID 
    Trim(txtid.Text)
        
        If 
    cmdfndnext.Tag "Next" Then
            Rem incriment ID number
            
    For Len(strIDTo 1 Step -1
                
    If Mid(strIDi1Like "[!0-9]" Then
                    strPrefix 
    Left(strIDi)
                    
    strSuffix Mid(strID1)
                    If 
    Len(strIDThen
                        strSuffix 
    Format(Val(strSuffix) + 1String(Len(strSuffix), "0"))
                    
    End If
                   Exit For
                
    End If
            
    Next i
            strID 
    strPrefix strSuffix
            txtid
    .Text strID
            
        End 
    If
        
        
    With Sheets("Life Member").Range("A:A")
            
    On Error Resume Next
            Set rngFound 
    = .Find(txtid.TextAfter:=.Cells(Rows.Count1), Lookat:=xlWholeLookIn:=xlValuesMatchCase:=True)
            
    On Error GoTo 0
        End With
        
        
    If rngFound Is Nothing Then
            
        
        
    '"my Answer- vb yes"

            MsgBox "ID not Found!!, Want to CReate?"
            

            txtname.Enabled = True
            txtstatus.Enabled = True
            txtreceipt.Enabled = True
            txtyear.Enabled = True

        Else

        
        '"my answer- vb no" 
    & exit sub


            With rngFound
    .EntireRow
                
                
                txtname
    .Text = .Cells(12).Text
                txtstatus
    .Text = .Cells(14).Text
                txtreceipt
    .Text = .Cells(15).Text
                txtyear
    .Text = .Cells(16).Text
                

            End With
        End 
    If
        
        
    cmdfndnext.Tag "Next"
    End Sub 
    Last edited by hkbhansali; 09-12-2016 at 01:48 AM.

  6. #6
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Add vbyes no code

    In the future, please keep in mind that the correct way to address this is not to submit a new post but to edit the post that needs code tags.

    Also I suggest you use CODE tags instead of PHP tags.

    Your code does not use the example I posted. Is there something that is not clear about the example? The point is that you assign the result of the MsgBox function to a variable, then test that variable using your If statement to determine how the user answered.

  7. #7
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Add vbyes no code

    Unless I'm misunderstanding this you already have the an IF Then Else End If code bloc which the macro can process without any further input, so I'm not sure why you want a Message Box. What does this bring to the party?
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Need help with VBA code. Tons of code seperated in two, second part of code doesn't work.
    By FragaGeddon in forum Excel Programming / VBA / Macros
    Replies: 20
    Last Post: 11-30-2015, 11:46 AM
  2. What is the variable 'vbyes' classified as?
    By dmasters4919 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-19-2015, 10:56 AM
  3. VBA MsgBox with vbYes and vbNo
    By sswcharlie in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-08-2015, 06:34 PM
  4. [SOLVED] Excel VB code. Message pops up while code running asking question. Code must not wait.
    By Heinrich Venter in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-28-2014, 06:10 AM
  5. [SOLVED] Return to InputBox based on Value AND vbYes/No
    By Nu2Java in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-18-2012, 11:44 AM
  6. [SOLVED] MsgBox, VBYes, VBNo
    By Richard in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-18-2006, 01:35 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1