Home > OS >  VBA Dictionary add texbox values to a dictionary
VBA Dictionary add texbox values to a dictionary

Time:07-08

I need some help on looping through all my textboxes and adding the values to a dictionary.

Currently, I'm adding all textboxes name's as the key the dictionary.

Dim dict as New Dictionary
Dim Week as Class1, wID as String
Dim ctrl as Control
    
For Each ctrl in UserForm1.Controls
If TypeName(ctrl) = "TextBox" Then
   
wID = ctrl.name 
    
IF dict.exists(wID) = TRUE Then
set Week = class1
else
set week = dict(wID)
dict.add wID, Week
End if
    
week.field1 = week.field1   Application.Username
week.field2 = week.field2   userform1.combox1.value
week.count = week.count   ctrl.Text 'this part i cant get to work, dont have the option for text or value

Set ReadItems = dict
End if
Next ctrl

I want to pass all the textboxes values in to week.count, similar to how all the textboxes names are added to wID (key)

appreciate all help.

Thanks

CodePudding user response:

I managed to figure out what I was trying to do.

Dim txtname as string, txtvalue as string

txtname = ctrl.name

txtvalue = userform1(txtname).value

which then I changed this bit to be:

week.count = week.count   txtvalue

now for each textbox the value entered is stored in the dictionary in .count

  • Related