Search and edit records using userform










0















i'm relatively new to VBA and have muddled my way through to almost achieving the system i set out to produce.



I have now reached a brick wall and have been smashing my head against it for some time, help with my paradigm (tome only i'm sure) would be very much appreciated!!



So i am able to search for records and populate my user form from that, what i would like to do is update the found record through the same form when clicking the update button which is present on said user form.



Private Sub btsearch_Click()
Dim totrows As Long
totrows = Worksheets("Report").Range("A1").CurrentRegion.Rows.Count
If Txtforename.Text = "" Then
MsgBox "Please enter guest name!!"
End If

For i = 2 To totrows
If Trim(Report.Cells(i, 1)) <> Trim(Txtforename.Text) And i = totrows Then
MsgBox "Guest Not Found"
End If
If Trim(Report.Cells(i, 1)) = Trim(Txtforename.Text) Then
Txtforename.Text = Report.Cells(i, 1)
Txtsurename.Text = Report.Cells(i, 2)
Cboidtype.Text = Report.Cells(i, 3)
txtidnumber.Text = Report.Cells(i, 4)
Cboroomno.Text = Report.Cells(i, 5)
txtcheckin.Text = Report.Cells(i, 6)
txtcheckout.Text = Report.Cells(i, 7)
Cbopaymenttype.Text = Report.Cells(i, 9)
Txttotalpayment.Text = Report.Cells(i, 10)
cmbouser.Text = Report.Cells(i, 11)
Exit For
End If
Next i

End Sub

Private Sub btnupdate_Click()

answer = MsgBox("Would you like to update guest details?", vbYesNo +
vbQuestion, "Update Record")
If answer = vbYes Then
Cells(currentrow, 1) = Txtforename.Text
Cells(currentrow, 2) = Txtsurename.Text
Cells(currentrow, 3) = Cboidtype.Text
Cells(currentrow, 4) = txtidnumber.Text
Cells(currentrow, 5) = Cboroomno.Text
Cells(currentrow, 6) = txtcheckin.Text
Cells(currentrow, 7) = txtcheckout.Text
Cells(currentrow, 9) = Cbopaymenttype.Text
Cells(currentrow, 10) = Txttotalpayment.Text
Cells(currentrow, 11) = cmbouser.Text
End If
End Sub









share|improve this question






















  • Seems like you just need a global variable currentrow which you populate from i when you locate the row for editing.

    – Tim Williams
    Nov 15 '18 at 20:42















0















i'm relatively new to VBA and have muddled my way through to almost achieving the system i set out to produce.



I have now reached a brick wall and have been smashing my head against it for some time, help with my paradigm (tome only i'm sure) would be very much appreciated!!



So i am able to search for records and populate my user form from that, what i would like to do is update the found record through the same form when clicking the update button which is present on said user form.



Private Sub btsearch_Click()
Dim totrows As Long
totrows = Worksheets("Report").Range("A1").CurrentRegion.Rows.Count
If Txtforename.Text = "" Then
MsgBox "Please enter guest name!!"
End If

For i = 2 To totrows
If Trim(Report.Cells(i, 1)) <> Trim(Txtforename.Text) And i = totrows Then
MsgBox "Guest Not Found"
End If
If Trim(Report.Cells(i, 1)) = Trim(Txtforename.Text) Then
Txtforename.Text = Report.Cells(i, 1)
Txtsurename.Text = Report.Cells(i, 2)
Cboidtype.Text = Report.Cells(i, 3)
txtidnumber.Text = Report.Cells(i, 4)
Cboroomno.Text = Report.Cells(i, 5)
txtcheckin.Text = Report.Cells(i, 6)
txtcheckout.Text = Report.Cells(i, 7)
Cbopaymenttype.Text = Report.Cells(i, 9)
Txttotalpayment.Text = Report.Cells(i, 10)
cmbouser.Text = Report.Cells(i, 11)
Exit For
End If
Next i

End Sub

Private Sub btnupdate_Click()

answer = MsgBox("Would you like to update guest details?", vbYesNo +
vbQuestion, "Update Record")
If answer = vbYes Then
Cells(currentrow, 1) = Txtforename.Text
Cells(currentrow, 2) = Txtsurename.Text
Cells(currentrow, 3) = Cboidtype.Text
Cells(currentrow, 4) = txtidnumber.Text
Cells(currentrow, 5) = Cboroomno.Text
Cells(currentrow, 6) = txtcheckin.Text
Cells(currentrow, 7) = txtcheckout.Text
Cells(currentrow, 9) = Cbopaymenttype.Text
Cells(currentrow, 10) = Txttotalpayment.Text
Cells(currentrow, 11) = cmbouser.Text
End If
End Sub









share|improve this question






















  • Seems like you just need a global variable currentrow which you populate from i when you locate the row for editing.

    – Tim Williams
    Nov 15 '18 at 20:42













0












0








0








i'm relatively new to VBA and have muddled my way through to almost achieving the system i set out to produce.



I have now reached a brick wall and have been smashing my head against it for some time, help with my paradigm (tome only i'm sure) would be very much appreciated!!



So i am able to search for records and populate my user form from that, what i would like to do is update the found record through the same form when clicking the update button which is present on said user form.



Private Sub btsearch_Click()
Dim totrows As Long
totrows = Worksheets("Report").Range("A1").CurrentRegion.Rows.Count
If Txtforename.Text = "" Then
MsgBox "Please enter guest name!!"
End If

For i = 2 To totrows
If Trim(Report.Cells(i, 1)) <> Trim(Txtforename.Text) And i = totrows Then
MsgBox "Guest Not Found"
End If
If Trim(Report.Cells(i, 1)) = Trim(Txtforename.Text) Then
Txtforename.Text = Report.Cells(i, 1)
Txtsurename.Text = Report.Cells(i, 2)
Cboidtype.Text = Report.Cells(i, 3)
txtidnumber.Text = Report.Cells(i, 4)
Cboroomno.Text = Report.Cells(i, 5)
txtcheckin.Text = Report.Cells(i, 6)
txtcheckout.Text = Report.Cells(i, 7)
Cbopaymenttype.Text = Report.Cells(i, 9)
Txttotalpayment.Text = Report.Cells(i, 10)
cmbouser.Text = Report.Cells(i, 11)
Exit For
End If
Next i

End Sub

Private Sub btnupdate_Click()

answer = MsgBox("Would you like to update guest details?", vbYesNo +
vbQuestion, "Update Record")
If answer = vbYes Then
Cells(currentrow, 1) = Txtforename.Text
Cells(currentrow, 2) = Txtsurename.Text
Cells(currentrow, 3) = Cboidtype.Text
Cells(currentrow, 4) = txtidnumber.Text
Cells(currentrow, 5) = Cboroomno.Text
Cells(currentrow, 6) = txtcheckin.Text
Cells(currentrow, 7) = txtcheckout.Text
Cells(currentrow, 9) = Cbopaymenttype.Text
Cells(currentrow, 10) = Txttotalpayment.Text
Cells(currentrow, 11) = cmbouser.Text
End If
End Sub









share|improve this question














i'm relatively new to VBA and have muddled my way through to almost achieving the system i set out to produce.



I have now reached a brick wall and have been smashing my head against it for some time, help with my paradigm (tome only i'm sure) would be very much appreciated!!



So i am able to search for records and populate my user form from that, what i would like to do is update the found record through the same form when clicking the update button which is present on said user form.



Private Sub btsearch_Click()
Dim totrows As Long
totrows = Worksheets("Report").Range("A1").CurrentRegion.Rows.Count
If Txtforename.Text = "" Then
MsgBox "Please enter guest name!!"
End If

For i = 2 To totrows
If Trim(Report.Cells(i, 1)) <> Trim(Txtforename.Text) And i = totrows Then
MsgBox "Guest Not Found"
End If
If Trim(Report.Cells(i, 1)) = Trim(Txtforename.Text) Then
Txtforename.Text = Report.Cells(i, 1)
Txtsurename.Text = Report.Cells(i, 2)
Cboidtype.Text = Report.Cells(i, 3)
txtidnumber.Text = Report.Cells(i, 4)
Cboroomno.Text = Report.Cells(i, 5)
txtcheckin.Text = Report.Cells(i, 6)
txtcheckout.Text = Report.Cells(i, 7)
Cbopaymenttype.Text = Report.Cells(i, 9)
Txttotalpayment.Text = Report.Cells(i, 10)
cmbouser.Text = Report.Cells(i, 11)
Exit For
End If
Next i

End Sub

Private Sub btnupdate_Click()

answer = MsgBox("Would you like to update guest details?", vbYesNo +
vbQuestion, "Update Record")
If answer = vbYes Then
Cells(currentrow, 1) = Txtforename.Text
Cells(currentrow, 2) = Txtsurename.Text
Cells(currentrow, 3) = Cboidtype.Text
Cells(currentrow, 4) = txtidnumber.Text
Cells(currentrow, 5) = Cboroomno.Text
Cells(currentrow, 6) = txtcheckin.Text
Cells(currentrow, 7) = txtcheckout.Text
Cells(currentrow, 9) = Cbopaymenttype.Text
Cells(currentrow, 10) = Txttotalpayment.Text
Cells(currentrow, 11) = cmbouser.Text
End If
End Sub






excel vba






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 15 '18 at 20:20









user3126785user3126785

289




289












  • Seems like you just need a global variable currentrow which you populate from i when you locate the row for editing.

    – Tim Williams
    Nov 15 '18 at 20:42

















  • Seems like you just need a global variable currentrow which you populate from i when you locate the row for editing.

    – Tim Williams
    Nov 15 '18 at 20:42
















Seems like you just need a global variable currentrow which you populate from i when you locate the row for editing.

– Tim Williams
Nov 15 '18 at 20:42





Seems like you just need a global variable currentrow which you populate from i when you locate the row for editing.

– Tim Williams
Nov 15 '18 at 20:42












2 Answers
2






active

oldest

votes


















1














Something like this should work (untested). The matched row is stored in a global variable so you can update it when you're finished editing



Dim CurrentRow As Range 'to store the matched row

Private Sub btsearch_Click()
Dim totrows As Long, i As Long, fName

fName = Trim(Txtforename.Text)
If Len(fName) = 0 Then
MsgBox "Please enter guest name!!"
Exit Sub
End If

totrows = Report.Range("A1").CurrentRegion.Rows.Count
Set CurrentRow = Nothing 'clear any previous row

For i = 2 To totrows
If Trim(Report.Cells(i, 1)) = fName Then
Set CurrentRow = Report.Rows(i)
LoadRow CurrentRow '<< save the matched row
Exit For
End If
Next i

If CurrentRow Is Nothing Then
MsgBox "not found!"
End If

End Sub

Private Sub btnupdate_Click()

If MsgBox("Would you like to update guest details?", _
vbYesNo + vbQuestion, "Update Record") = vbYes Then

SaveRow CurrentRow

End If
End Sub

'load a row of data into the userform
Sub LoadRow(rw As Range)
With rw
Txtforename.Text = .Cells(1).Value
Txtsurename.Text = .Cells(2).Value
Cboidtype.Text = .Cells(3).Value
'etc etc
End With
End Sub

'save the userform data back to the sheet
Sub SaveRow(rw As Range)
With rw
.Cells(1).Value = Txtforename.Text
.Cells(2).Value = Txtsurename.Text
.Cells(3).Value = Cboidtype.Text
'etc etc
End With
End Sub





share|improve this answer























  • Thank you very much tim, tried the code with no joy, am currently mobile so unable to give further details. Once I arrive home I will update. Thanks again

    – user3126785
    Nov 16 '18 at 7:53











  • Hey tim my apologies with the slow reply, been bogged down with this one, the code above doesn't seem to achieve what i desired. The search isn't effective and it submits data but only to the active worksheet and not to the same row as the data. Thanks again for your attempted assitance!!

    – user3126785
    Nov 18 '18 at 16:16











  • CurrentRow only gets populated by the search method, so I'm not sure how my code as posted could ever update the wrong sheet, unless Report is not the codename of your data sheet. You use both Worksheets("Report") and just Report in your posted code, so I assumed they represented the same thing.

    – Tim Williams
    Nov 18 '18 at 20:19












  • Finally figured it out thanks Tim, had to go a long way round but everything is working now. Thank you for your time and effort!!!

    – user3126785
    Nov 19 '18 at 14:57


















0














First thing I would check is the result value of the MsgBox. MsgBox always returns an integer, and answer is a variant.

Secondly I would declare answer as an integer. Together it could become this :


. . .
Dim answer As Integer
answer = Msgbox("Would you ... ecord")
Debug.Print "' answer := " & answer ' display result in immediate-window
MsgBox "' answer := " & answer ' or display the result with a msgbox
If answer = vbYes Then
Debug.Print "' then"
' while you are busy debugging, display this value too
Debug.Print "' currentrow := " & currentrow
. . .
Else
Debug.Print "' else"
End If
. . .





share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53327314%2fsearch-and-edit-records-using-userform%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Something like this should work (untested). The matched row is stored in a global variable so you can update it when you're finished editing



    Dim CurrentRow As Range 'to store the matched row

    Private Sub btsearch_Click()
    Dim totrows As Long, i As Long, fName

    fName = Trim(Txtforename.Text)
    If Len(fName) = 0 Then
    MsgBox "Please enter guest name!!"
    Exit Sub
    End If

    totrows = Report.Range("A1").CurrentRegion.Rows.Count
    Set CurrentRow = Nothing 'clear any previous row

    For i = 2 To totrows
    If Trim(Report.Cells(i, 1)) = fName Then
    Set CurrentRow = Report.Rows(i)
    LoadRow CurrentRow '<< save the matched row
    Exit For
    End If
    Next i

    If CurrentRow Is Nothing Then
    MsgBox "not found!"
    End If

    End Sub

    Private Sub btnupdate_Click()

    If MsgBox("Would you like to update guest details?", _
    vbYesNo + vbQuestion, "Update Record") = vbYes Then

    SaveRow CurrentRow

    End If
    End Sub

    'load a row of data into the userform
    Sub LoadRow(rw As Range)
    With rw
    Txtforename.Text = .Cells(1).Value
    Txtsurename.Text = .Cells(2).Value
    Cboidtype.Text = .Cells(3).Value
    'etc etc
    End With
    End Sub

    'save the userform data back to the sheet
    Sub SaveRow(rw As Range)
    With rw
    .Cells(1).Value = Txtforename.Text
    .Cells(2).Value = Txtsurename.Text
    .Cells(3).Value = Cboidtype.Text
    'etc etc
    End With
    End Sub





    share|improve this answer























    • Thank you very much tim, tried the code with no joy, am currently mobile so unable to give further details. Once I arrive home I will update. Thanks again

      – user3126785
      Nov 16 '18 at 7:53











    • Hey tim my apologies with the slow reply, been bogged down with this one, the code above doesn't seem to achieve what i desired. The search isn't effective and it submits data but only to the active worksheet and not to the same row as the data. Thanks again for your attempted assitance!!

      – user3126785
      Nov 18 '18 at 16:16











    • CurrentRow only gets populated by the search method, so I'm not sure how my code as posted could ever update the wrong sheet, unless Report is not the codename of your data sheet. You use both Worksheets("Report") and just Report in your posted code, so I assumed they represented the same thing.

      – Tim Williams
      Nov 18 '18 at 20:19












    • Finally figured it out thanks Tim, had to go a long way round but everything is working now. Thank you for your time and effort!!!

      – user3126785
      Nov 19 '18 at 14:57















    1














    Something like this should work (untested). The matched row is stored in a global variable so you can update it when you're finished editing



    Dim CurrentRow As Range 'to store the matched row

    Private Sub btsearch_Click()
    Dim totrows As Long, i As Long, fName

    fName = Trim(Txtforename.Text)
    If Len(fName) = 0 Then
    MsgBox "Please enter guest name!!"
    Exit Sub
    End If

    totrows = Report.Range("A1").CurrentRegion.Rows.Count
    Set CurrentRow = Nothing 'clear any previous row

    For i = 2 To totrows
    If Trim(Report.Cells(i, 1)) = fName Then
    Set CurrentRow = Report.Rows(i)
    LoadRow CurrentRow '<< save the matched row
    Exit For
    End If
    Next i

    If CurrentRow Is Nothing Then
    MsgBox "not found!"
    End If

    End Sub

    Private Sub btnupdate_Click()

    If MsgBox("Would you like to update guest details?", _
    vbYesNo + vbQuestion, "Update Record") = vbYes Then

    SaveRow CurrentRow

    End If
    End Sub

    'load a row of data into the userform
    Sub LoadRow(rw As Range)
    With rw
    Txtforename.Text = .Cells(1).Value
    Txtsurename.Text = .Cells(2).Value
    Cboidtype.Text = .Cells(3).Value
    'etc etc
    End With
    End Sub

    'save the userform data back to the sheet
    Sub SaveRow(rw As Range)
    With rw
    .Cells(1).Value = Txtforename.Text
    .Cells(2).Value = Txtsurename.Text
    .Cells(3).Value = Cboidtype.Text
    'etc etc
    End With
    End Sub





    share|improve this answer























    • Thank you very much tim, tried the code with no joy, am currently mobile so unable to give further details. Once I arrive home I will update. Thanks again

      – user3126785
      Nov 16 '18 at 7:53











    • Hey tim my apologies with the slow reply, been bogged down with this one, the code above doesn't seem to achieve what i desired. The search isn't effective and it submits data but only to the active worksheet and not to the same row as the data. Thanks again for your attempted assitance!!

      – user3126785
      Nov 18 '18 at 16:16











    • CurrentRow only gets populated by the search method, so I'm not sure how my code as posted could ever update the wrong sheet, unless Report is not the codename of your data sheet. You use both Worksheets("Report") and just Report in your posted code, so I assumed they represented the same thing.

      – Tim Williams
      Nov 18 '18 at 20:19












    • Finally figured it out thanks Tim, had to go a long way round but everything is working now. Thank you for your time and effort!!!

      – user3126785
      Nov 19 '18 at 14:57













    1












    1








    1







    Something like this should work (untested). The matched row is stored in a global variable so you can update it when you're finished editing



    Dim CurrentRow As Range 'to store the matched row

    Private Sub btsearch_Click()
    Dim totrows As Long, i As Long, fName

    fName = Trim(Txtforename.Text)
    If Len(fName) = 0 Then
    MsgBox "Please enter guest name!!"
    Exit Sub
    End If

    totrows = Report.Range("A1").CurrentRegion.Rows.Count
    Set CurrentRow = Nothing 'clear any previous row

    For i = 2 To totrows
    If Trim(Report.Cells(i, 1)) = fName Then
    Set CurrentRow = Report.Rows(i)
    LoadRow CurrentRow '<< save the matched row
    Exit For
    End If
    Next i

    If CurrentRow Is Nothing Then
    MsgBox "not found!"
    End If

    End Sub

    Private Sub btnupdate_Click()

    If MsgBox("Would you like to update guest details?", _
    vbYesNo + vbQuestion, "Update Record") = vbYes Then

    SaveRow CurrentRow

    End If
    End Sub

    'load a row of data into the userform
    Sub LoadRow(rw As Range)
    With rw
    Txtforename.Text = .Cells(1).Value
    Txtsurename.Text = .Cells(2).Value
    Cboidtype.Text = .Cells(3).Value
    'etc etc
    End With
    End Sub

    'save the userform data back to the sheet
    Sub SaveRow(rw As Range)
    With rw
    .Cells(1).Value = Txtforename.Text
    .Cells(2).Value = Txtsurename.Text
    .Cells(3).Value = Cboidtype.Text
    'etc etc
    End With
    End Sub





    share|improve this answer













    Something like this should work (untested). The matched row is stored in a global variable so you can update it when you're finished editing



    Dim CurrentRow As Range 'to store the matched row

    Private Sub btsearch_Click()
    Dim totrows As Long, i As Long, fName

    fName = Trim(Txtforename.Text)
    If Len(fName) = 0 Then
    MsgBox "Please enter guest name!!"
    Exit Sub
    End If

    totrows = Report.Range("A1").CurrentRegion.Rows.Count
    Set CurrentRow = Nothing 'clear any previous row

    For i = 2 To totrows
    If Trim(Report.Cells(i, 1)) = fName Then
    Set CurrentRow = Report.Rows(i)
    LoadRow CurrentRow '<< save the matched row
    Exit For
    End If
    Next i

    If CurrentRow Is Nothing Then
    MsgBox "not found!"
    End If

    End Sub

    Private Sub btnupdate_Click()

    If MsgBox("Would you like to update guest details?", _
    vbYesNo + vbQuestion, "Update Record") = vbYes Then

    SaveRow CurrentRow

    End If
    End Sub

    'load a row of data into the userform
    Sub LoadRow(rw As Range)
    With rw
    Txtforename.Text = .Cells(1).Value
    Txtsurename.Text = .Cells(2).Value
    Cboidtype.Text = .Cells(3).Value
    'etc etc
    End With
    End Sub

    'save the userform data back to the sheet
    Sub SaveRow(rw As Range)
    With rw
    .Cells(1).Value = Txtforename.Text
    .Cells(2).Value = Txtsurename.Text
    .Cells(3).Value = Cboidtype.Text
    'etc etc
    End With
    End Sub






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 16 '18 at 0:54









    Tim WilliamsTim Williams

    89.1k97087




    89.1k97087












    • Thank you very much tim, tried the code with no joy, am currently mobile so unable to give further details. Once I arrive home I will update. Thanks again

      – user3126785
      Nov 16 '18 at 7:53











    • Hey tim my apologies with the slow reply, been bogged down with this one, the code above doesn't seem to achieve what i desired. The search isn't effective and it submits data but only to the active worksheet and not to the same row as the data. Thanks again for your attempted assitance!!

      – user3126785
      Nov 18 '18 at 16:16











    • CurrentRow only gets populated by the search method, so I'm not sure how my code as posted could ever update the wrong sheet, unless Report is not the codename of your data sheet. You use both Worksheets("Report") and just Report in your posted code, so I assumed they represented the same thing.

      – Tim Williams
      Nov 18 '18 at 20:19












    • Finally figured it out thanks Tim, had to go a long way round but everything is working now. Thank you for your time and effort!!!

      – user3126785
      Nov 19 '18 at 14:57

















    • Thank you very much tim, tried the code with no joy, am currently mobile so unable to give further details. Once I arrive home I will update. Thanks again

      – user3126785
      Nov 16 '18 at 7:53











    • Hey tim my apologies with the slow reply, been bogged down with this one, the code above doesn't seem to achieve what i desired. The search isn't effective and it submits data but only to the active worksheet and not to the same row as the data. Thanks again for your attempted assitance!!

      – user3126785
      Nov 18 '18 at 16:16











    • CurrentRow only gets populated by the search method, so I'm not sure how my code as posted could ever update the wrong sheet, unless Report is not the codename of your data sheet. You use both Worksheets("Report") and just Report in your posted code, so I assumed they represented the same thing.

      – Tim Williams
      Nov 18 '18 at 20:19












    • Finally figured it out thanks Tim, had to go a long way round but everything is working now. Thank you for your time and effort!!!

      – user3126785
      Nov 19 '18 at 14:57
















    Thank you very much tim, tried the code with no joy, am currently mobile so unable to give further details. Once I arrive home I will update. Thanks again

    – user3126785
    Nov 16 '18 at 7:53





    Thank you very much tim, tried the code with no joy, am currently mobile so unable to give further details. Once I arrive home I will update. Thanks again

    – user3126785
    Nov 16 '18 at 7:53













    Hey tim my apologies with the slow reply, been bogged down with this one, the code above doesn't seem to achieve what i desired. The search isn't effective and it submits data but only to the active worksheet and not to the same row as the data. Thanks again for your attempted assitance!!

    – user3126785
    Nov 18 '18 at 16:16





    Hey tim my apologies with the slow reply, been bogged down with this one, the code above doesn't seem to achieve what i desired. The search isn't effective and it submits data but only to the active worksheet and not to the same row as the data. Thanks again for your attempted assitance!!

    – user3126785
    Nov 18 '18 at 16:16













    CurrentRow only gets populated by the search method, so I'm not sure how my code as posted could ever update the wrong sheet, unless Report is not the codename of your data sheet. You use both Worksheets("Report") and just Report in your posted code, so I assumed they represented the same thing.

    – Tim Williams
    Nov 18 '18 at 20:19






    CurrentRow only gets populated by the search method, so I'm not sure how my code as posted could ever update the wrong sheet, unless Report is not the codename of your data sheet. You use both Worksheets("Report") and just Report in your posted code, so I assumed they represented the same thing.

    – Tim Williams
    Nov 18 '18 at 20:19














    Finally figured it out thanks Tim, had to go a long way round but everything is working now. Thank you for your time and effort!!!

    – user3126785
    Nov 19 '18 at 14:57





    Finally figured it out thanks Tim, had to go a long way round but everything is working now. Thank you for your time and effort!!!

    – user3126785
    Nov 19 '18 at 14:57













    0














    First thing I would check is the result value of the MsgBox. MsgBox always returns an integer, and answer is a variant.

    Secondly I would declare answer as an integer. Together it could become this :


    . . .
    Dim answer As Integer
    answer = Msgbox("Would you ... ecord")
    Debug.Print "' answer := " & answer ' display result in immediate-window
    MsgBox "' answer := " & answer ' or display the result with a msgbox
    If answer = vbYes Then
    Debug.Print "' then"
    ' while you are busy debugging, display this value too
    Debug.Print "' currentrow := " & currentrow
    . . .
    Else
    Debug.Print "' else"
    End If
    . . .





    share|improve this answer





























      0














      First thing I would check is the result value of the MsgBox. MsgBox always returns an integer, and answer is a variant.

      Secondly I would declare answer as an integer. Together it could become this :


      . . .
      Dim answer As Integer
      answer = Msgbox("Would you ... ecord")
      Debug.Print "' answer := " & answer ' display result in immediate-window
      MsgBox "' answer := " & answer ' or display the result with a msgbox
      If answer = vbYes Then
      Debug.Print "' then"
      ' while you are busy debugging, display this value too
      Debug.Print "' currentrow := " & currentrow
      . . .
      Else
      Debug.Print "' else"
      End If
      . . .





      share|improve this answer



























        0












        0








        0







        First thing I would check is the result value of the MsgBox. MsgBox always returns an integer, and answer is a variant.

        Secondly I would declare answer as an integer. Together it could become this :


        . . .
        Dim answer As Integer
        answer = Msgbox("Would you ... ecord")
        Debug.Print "' answer := " & answer ' display result in immediate-window
        MsgBox "' answer := " & answer ' or display the result with a msgbox
        If answer = vbYes Then
        Debug.Print "' then"
        ' while you are busy debugging, display this value too
        Debug.Print "' currentrow := " & currentrow
        . . .
        Else
        Debug.Print "' else"
        End If
        . . .





        share|improve this answer















        First thing I would check is the result value of the MsgBox. MsgBox always returns an integer, and answer is a variant.

        Secondly I would declare answer as an integer. Together it could become this :


        . . .
        Dim answer As Integer
        answer = Msgbox("Would you ... ecord")
        Debug.Print "' answer := " & answer ' display result in immediate-window
        MsgBox "' answer := " & answer ' or display the result with a msgbox
        If answer = vbYes Then
        Debug.Print "' then"
        ' while you are busy debugging, display this value too
        Debug.Print "' currentrow := " & currentrow
        . . .
        Else
        Debug.Print "' else"
        End If
        . . .






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 15 '18 at 23:32

























        answered Nov 15 '18 at 20:42









        JonRoJonRo

        1363




        1363



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53327314%2fsearch-and-edit-records-using-userform%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            How to read a connectionString WITH PROVIDER in .NET Core?

            In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

            Museum of Modern and Contemporary Art of Trento and Rovereto