The Student Room Group

Importing .dat into vba quickly

I know of one long way of importing a .dat file into vba.


txtdj_last_name.text = djs.dj_lname
txtdj_first_name.Text = djs.dj_fname
txtdj_house_number.Text = djs.dj_hnum


Intead of doing this like 20 times is there a quicker way?

I have found a shorter way for clearing all fields.
For Each ctl In Me.Controls
If ctl.ControlType = acTextBox Then
' set the values in the fields to null
ctl.Value = ""
End If
Next


Please can somebody help a quicker way also a quicker way on writing into the file.
Reply 1
Ok I think I might be heading in the right direction. But it might not work.

I've got;
For Each ctl In Me.Controls
If ctl.ControlType = acTextBox Then
ctl.value = djs.???
End If
Next

djs. is the filename... I can't think what needs to go there. I've tried value what doesnt't work. I might need to have the data saved using the same name and then I might be able to get it.
Reply 2
I have given up and just went the long way. If i could only now know how to delete the record from the fixed length file :wink:
Reply 3
There is no concept of control arrays in VBA, which would be a solution under VB6. Your best bet would be a solution that doesn't use hundreds of text boxes - either a data grid control or list boxes.

Latest

Trending

Trending