• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

How do I resolve Run time error"1004"?

Hi Hakim ,

Please post your macro , along with a screenshot of the line at which the error occurs ; if possible , please upload your workbook.

Narayan
 
I have 3 problems. 1st is with Vlookup.
I am uploading screenshots along with the workbook. Please go to 'find student button' in the 'interface' worksheet. It shows the error '1004'. Please if you can help me. And the second issue is with the 'Edit Record Button'. I have inseted this to edit the recoded data. But it doesn't load the data in the remaining textboxes as I have added the code to load the recorded data.
 

Attachments

  • Inteface.xlsm
    118.5 KB · Views: 1
I have 3 problems. 1st is with Vlookup.
I am uploading screenshots along with the workbook. Please go to 'find student button' in the 'interface' worksheet. It shows the error '1004'. Please if you can help me. And the second issue is with the 'Edit Record Button'. I have inseted this to edit the recoded data. But it doesn't load the data in the remaining textboxes as I have added the code to load the recorded data.
Hi,

The problem with find student is that your not telling the code where to look for the student name and you're comparing text with a number in your VLOOKUP. Textboxes return text and if you want to use it as a number then you must convert it. This line now works for find the student name but you will have to correct other lines of code which all contain the same error

Note the convert to long CLNG and the addition of a worksheet.

Code:
studentname = WorksheetFunction.VLookup(CLng(ComboBox1), Sheets("Details").Range("A:N"), 2, False)
 
Thank you Mr.Mike... Your code was very helpful. And is working properly. If you please help me with 'Edit record button' as well. I have inserted that form to edit the recorded data in the 'Details' worksheet. It doesn't load the data in the userform when I enter the regstration number. Please if you help me out.
 
Thank you Mr.Mike... Your code was very helpful. And is working properly. If you please help me with 'Edit record button' as well. I have inserted that form to edit the recorded data in the 'Details' worksheet. It doesn't load the data in the userform when I enter the regstration number. Please if you help me out.
hI,

I fixed the code to edit or add a new record. See attached workbook. You are making the same mistakes as in the other routine by comparing text from a textbox with a number on the workskeet. Also see my method of finding the empty row.

You also need to consider who will use this workbook. If it's people other than you then you need to error trap the inputs because as you can see I used gibberish while testing.

Code:
Sub EditAdd()
Dim TheRow As Long
Dim emptyRow As Long
If frmeditrecord.editstudent1.Value <> "" Then
  flag = False
  ID = CLng(frmeditrecord.editstudent1.Value)
  emptyRow = Sheets("Details").Cells(Rows.Count, "A").End(xlUp).Row + 1
  On Error Resume Next
  TheRow = Application.Match(ID, Sheets("Details").Columns(1), 0)
  On Error GoTo 0
If TheRow > 0 Then
flag = True
  For j = 2 To 13
  Sheets("Details").Cells(TheRow, j).Value = frmeditrecord.Controls("editstudent" & j).Value
  Next j
 
End If
  If flag = False Then
  For j = 1 To 13
  Cells(emptyRow, j).Value = frmeditrecord.Controls("editstudent" & j).Value
  Next j
  End If

End If

End Sub
 

Attachments

  • Inteface.xlsm
    111.3 KB · Views: 0
Dear Mr.Mike, I once again owe you humble thanks. Your help is always helpful to me. The edit sub is working 100%. But if you please help me with the GetData sub. Thats what I am not getting properly. Thank you so much.
 
Dear Mr.Mike, I once again owe you humble thanks. Your help is always helpful to me. The edit sub is working 100%. But if you please help me with the GetData sub. Thats what I am not getting properly. Thank you so much.
Hi,

All 5 buttons on the interface sheet now work. Where required the comboboxes with the registration numbers populate automatically.
 

Attachments

  • Inteface.xlsm
    116.6 KB · Views: 1
I have uploaded the file which I had practiced. And I am following that codes. When you enter the ID number which is already recorded, it loads all the textboxes with the relevant data. Your help is fully working. But I want to apply the GetData sub as well.
 

Attachments

  • checkkk.xlsm
    20.1 KB · Views: 0
I have uploaded the file which I had practiced. And I am following that codes. When you enter the ID number which is already recorded, it loads all the textboxes with the relevant data. Your help is fully working. But I want to apply the GetData sub as well.
Try it again, there was a change event that was calling code at the wrong time
 

Attachments

  • Inteface.xlsm
    116.8 KB · Views: 2
Thank you once again dear Sir. I have checked it. My issue still persists. As in the case of the 'xlsm' file, when you want to edit the data in the work sheet, suppose, ID#1. When you enter the ID#1 in the ID textbox in the userform, the other three textboxes automatically loads the relevant data. In the interface file, it doesn't happen. The data is editable, but it doesn't get the data automatically from the worksheet once you enter the registration number. I have shared both the files. Please check the 'checkkk.xlsm' file first. Click on the command button and enter 1 in the ID bar. You will see what my problem is. I have entered the codes in the modules in both the files. The problem is that the interface file's 'GetData_sub' doesn't work.
 

Attachments

  • Inteface(1).xlsm
    116.8 KB · Views: 0
  • checkkk.xlsm
    20.1 KB · Views: 1
Back
Top