Hello I get the following error when NextButton Clicked. Can anyone help me to reoslve the same
FYI : both forms are VbModeless
Could not Find the specific object
Run-Time Error -'2147024809(80070057)
at this line in userform2 CmdNext_click coding :
Ws.Cells(curRow, i).Value = frm2.Controls("txtFrm2" & i).Value
also shared the file:
https://www.dropbox.com/s/55j2wdwjdg3bqlf/Userform-workSheets-TxtBxsFrmload.xlsm?dl=0
in Module1
in Userform1
in Userform2
Thankx NimishK
FYI : both forms are VbModeless
Could not Find the specific object
Run-Time Error -'2147024809(80070057)
at this line in userform2 CmdNext_click coding :
Ws.Cells(curRow, i).Value = frm2.Controls("txtFrm2" & i).Value
also shared the file:
https://www.dropbox.com/s/55j2wdwjdg3bqlf/Userform-workSheets-TxtBxsFrmload.xlsm?dl=0
in Module1
Code:
Option Explicit
Public Const StartRow As Long = 2
Public row As Long
Public curRow As Long
Public Ws As Worksheet
Public uf_frmTarget As UserForm1
Public frm2 As UserForm2
Public curRec As Integer
in Userform1
Code:
Option Explicit
Private Sub cmdNext_Click()
Dim Ws As Worksheet
Set Ws = Worksheets("Sheet2")
Dim i As Integer
i = 1
If curRow < 5 Then 'lastRow Then
For i = 1 To 2
Ws.Cells(curRow, i).Value = frm2.Controls("txtFrm2" & i).Value
'Ws.Cells(curRow, i).Value = frm2.txtFrm2(i).Value
Next i
curRec = curRec + 1
curRow = curRow + 1
UserForm1.lblSrNo.Caption = Format$(curRec)
GetRecord curRow
End If
Rows(curRow).Select
End Sub
Private Sub cmdPrevious_Click()
Dim Ws As Worksheet
Set Ws = Worksheets("Sheet2")
If curRec > 1 Then 'lastRow Then
curRec = curRec - 1
curRow = curRow - 1
UserForm1.lblSrNo.Caption = Format$(curRec)
GetRecord curRow
End If
Rows(curRow).Select
End Sub
Private Sub cmdUF2_Click()
Dim Ws As Worksheet
Set frm2 = New UserForm2
Load frm2
frm2.Show vbModeless
frm2.Caption = "Trial"
Set Ws = Worksheets("Sheet2")
Ws.Activate
curRow = 2
GetRecord curRow
End Sub
Private Sub UserForm_Initialize()
curRec = 1
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
On Local Error Resume Next
frm2.Hide
End Sub
Sub GetRecord(ByVal row As Long)
Dim Ws As Worksheet
Set Ws = Worksheets("Sheet2")
UserForm1.Tag = xlOff
Ws.Activate
If row < StartRow Then row = StartRow
Rows(row).Select
curRec = curRow - 1
UserForm1.lblSrNo.Caption = Format$(curRec)
End Sub
in Userform2
Code:
Private Sub UserForm_Activate()
Set frm2 = New UserForm2
frm2.Top = 210
frm2.Left = 0
End Sub
Private Sub UserForm_Initialize()
Dim Ws As Worksheet
Set Ws = Worksheets("Sheet2")
Ws.Activate
Dim txtBxFrm2 As Control
Dim lablFrm2 As Control
Dim i As Integer
Dim x As Integer
Dim y As Integer
y = 10
x = 10
For i = 1 To 2
Set txtBxFrm2 = Controls.Add("Forms.TextBox.1")
Set lablFrm2 = Controls.Add("Forms.Label.1")
With lablFrm2
.Name = "lblfrm2"
.Height = 15.75
.Width = 15 * 5
.Left = x
.Top = y
.BackStyle = 0
.Caption = Sheet2.Cells(1, i).Value
End With
With txtBxFrm2
.Name = "txtFrm2"
.Height = 18
.Width = 116
.Left = x
.Top = y + 10
.Value = Ws.Cells(StartRow, i).Value
.Font.Name = "Calibri"
.Font.Size = "11"
End With
x = x + 142
Next i
End Sub
Last edited: