0

I have a table as below.

Table with variables and values

I would like to assign values to variables by looping through the table,

myDSN="B"
Password="D". 

I can loop through the table wiht DAO recordset. I tried daRs!AAA ="""& daRs!AAB&""" and it obviously did not work becuase VBA thinks that I was trying to update the table. Any idea how to loop through this table to assign values to variables, both of which are in a table?

Many thanks.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
davidzxc574
  • 471
  • 1
  • 8
  • 21
  • to loop through the table – davidzxc574 Apr 11 '18 at 02:20
  • That's not how variables are declared, or assigned values. I'd suggest you start with a tutorial about using variables [like this one](https://powerspreadsheets.com/declare-variables-vba-excel/) - then there's a good chance you'll be able to solve this issue yourself. – ashleedawg Apr 11 '18 at 02:21
  • After that, look for examples of how to loop through a table. For starters there are a number of examples [on this question](https://stackoverflow.com/q/5864160/8112776) (which was the first result in a Google search for ["loop through an Access table"](https://www.google.ca/search?q=access+loop+through+a+table). **Please,** you need to **at least attempt to solve a problem yourself with a bit of research** before posting a question. – ashleedawg Apr 11 '18 at 02:25
  • Possible duplicate of [Code to loop through all records in MS Access](https://stackoverflow.com/questions/5864160/code-to-loop-through-all-records-in-ms-access) I'd suggest you **delete this question** (otherwise it will be closed anyway but just creates work for more people) and after you have researched, tried a few things, if you're still having issues then ask a new question but first **read "[ask]" and well as "[mcve]" and also [help/on-topic].** – ashleedawg Apr 11 '18 at 02:25
  • dude, I know how to loop through a table with ADO or DAO recordset. And I know how to delcare a variable and assgin it with a value. My question is how to assign values to variables when boths of them are in a table. Obviously you have to loop through a table to do so. But I dont know how and if anyone did it before. Otherwise I will have to type Dim variable1 as string , and variable1="value1".....many times/. – davidzxc574 Apr 11 '18 at 02:30
  • AND PLEASE UNDERSTAND MY QUESTION CAREFULLY!! – davidzxc574 Apr 11 '18 at 02:37
  • Are you wanting to add a calculated field to a table so as if one of the fields the calculation is based on changes the field updates; or insert data into a field in an automated way such as a query as in field myDSN for all records (or where record field = x) are set to "B"? – sunsetsurf Apr 11 '18 at 03:06

0 Answers0