self generation of form if record exists

WelshBL

New Member
Joined
May 3, 2017
Messages
15
hi guys,
I have got the code of
Code:
If Not IsEmpty(UserForm1.Fillin1) Then
     flag = False
     i = 0
     ID = UserForm1.Fillin1
     Do While Cells(i + 1, 1).Value <> ""
         If Cells(i + 1, 1).Value = ID Then
             flag = True
             For j = 2 To 17
             UserForm1.Controls("Fillin" & j).Value = Cells(i + 1, j).Value
             Next j
         End If
         i = i + 1
     Loop
     If flag = False Then
         For j = 2 To 17
             UserForm1.Controls("Fillin" & j).Value = ""
         Next j
     End If
Else
     ClearForm
End If

however if I use a numeric value in the primary field it is not reading the rest of the record. if I put text in it works can anyone point me in right direction to be able to get it to allow both number and text as a primary search function

any help would be appreciated.
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
UserForm1.Fillin1 is going to return a text (string) value but Cells(i + 1, 1).Value will return either text or number depending on the content of the cell. Try changing the If statement to this:

Code:
         If CStr(Cells(i + 1, 1).Value) = CStr(ID) Then

WBD
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top