You can use this.
Checking if is textfield,label,etc and get the data you want
For i As Integer = 0 To Self.ControlCount-1
// Check if the control is a TextField
If Self.Control(i) IsA TextField Then
// Cast the control to a TextField in order to access the Text property
TextField(Self.Control(i)).Text = "Found You!"
End If
Next Isa
FWIW, a recordset will never be nil unless there is a database error. So rs <> nil doesn’t begin to be useful since it hides the real problem.
You MUST check the database.error bit and retrieve the database.errormessage for it to be useful. Xojo does not throw an exception on database error so you have to check it after every database action.
@Bob for your advise. @Loannis, seems that still doesn’t solve my problem, even though I can get the type of the control, how can I assign the correct value in the database record to the correct field on the UI?
I personally avoid creating generic entry screens. I prefer a well crafted, intelligent data entry screen. But, if you need a generic screen, create a containercontrol with a label and a textfield. Loop through the fields in the recordset and create a new containter for each. Set the label to the field name and the textfield to the value. Then embed it at the next “row” on the screen and keep a reference to it in an array for when you want to write them back out.
Alternately, use a listbox with 2 columns - label and value - so you can scroll the view easily.
[quote=259030:@Tony Lam]@Bob for your advise. @Loannis, seems that still doesn’t solve my problem, even though I can get the type of the control, how can I assign the correct value in the database record to the correct field on the UI?[/quote]
You can proceed with select case or with if then loop.
If TextField(Self.Control(i)).Name = "FieldUserCode" then
"Your code"
end if
Preferred is the select case