Hello i am new this is my first post, had a look and the site seems very helpful like it so far!
What i want to achieve?
Use patients name and retrieve 2 fields ( got it working but works with Integers only ) - this fields should not be editable
After locating the patient to add in the row in the end for the same patient other info that the user will input.
What i got so far
What i want to achieve?
Use patients name and retrieve 2 fields ( got it working but works with Integers only ) - this fields should not be editable
After locating the patient to add in the row in the end for the same patient other info that the user will input.
What i got so far
Code:
Dim id As Integer, i As Integer, j As Integer, flag As Boolean
'Code to retrieve data based on ID - to be changed to string ( patients name )
Sub GetData()
If IsNumeric(UserForm1.TextBox1.Value) Then
flag = False
i = 0
id = UserForm1.TextBox1.Value
Do While Cells(i + 1, 1).Value <> ""
If Cells(i + 1, 1).Value = id Then
flag = True
For j = 2 To 3
UserForm1.Controls("TextBox" & j).Value = Cells(i + 1, j).Value
Next j
End If
i = i + 1
Loop
If flag = False Then
For j = 2 To 3
UserForm1.Controls("TextBox" & j).Value = ""
Next j
End If
'Else
' ClearForm
End If
End Sub
'Sub to Add extra fields on the selected patient
Sub EditAdd()
Dim emptyCol As Long
If UserForm1.TextBox1.Value <> "" Then
flag = False
i = 0
id = UserForm1.TextBox1.Value
'emptyCol = WorksheetFunction.CountA(Range("A:Z")) + 1
emptyCol = WorksheetFunction.CountA(Columns(1)) + 1
Do While Cells(i + 1, 1).Value <> ""
If Cells(i + 1, 1).Value = id Then
flag = True
For j = 2 To 3
Cells(i + 1, j).Value = UserForm1.Controls("TextBox" & j).Value
Next j
End If
i = i + 1
Loop
If flag = False Then
For j = 1 To 3
Cells(emptyCol, j).Value = UserForm1.Controls("TextBox" & j).Value
Next j
End If
End If
End Sub