I try to use the first recordset(rst) as a variable, to get the colown name for the second recordset(rst1)...that I have to use update the current record in rst1...
Set Conn = CurrentProject.Connection Set rst = New ADODB.Recordset Set rst1 = New ADODB.Recordset
Sql = "select * from " & table_name & " where 1=0" rst.Open Sql, Conn, adOpenDynamic, adLockOptimistic
For i = 0 To rst.Fields.Count - 1 If rst.Fields(i).Name <> "ID" Then
Sql = "select " & rst.Fields(i).Namefrom & " & table_name & " where " & rst.Fields(i).Name & "<>''" rst1.Open Sql, Conn, adOpenDynamic, adLockOptimistic Do Until rst1.EOF
If Not rst1.EOF Then Rec1 = rst1!rst.Fields(i).Name rst1!rst.Fields(i).Name = Replace(Rec1, Fra, Til) rst1.Update End If
rst1.MoveNext Loop rst1.Close End If Next i rst.Close
Recordset: sets of records - strukturændringer er mere noget med tabledefs (eller sql) - men prøv: det burde give en fejlmeddelelse gående på at feltnavnet er readonly. Min fornemmelse går på det ville være et dirty design hvis update skulle indbefatte feltnavnændringer.
adodb.recordset.fields(i).name er en readonly property i min vba editor - objekt browser (f2) Skulle angiveligt være noget lettere at ændre feltnavne i dao - selv om jeg godt ved at det ikke er det spørgsmålet går på.
is it possible for you to send me an example of your dB with a step for step explanation (på dansk) of what you are trying to do? ekspertenATsanthell.dk AT = @
.. Ændre alle felter i alle kolonner.. If i just did this then on the table you sent, I could just do it in one single SQL Update
but I am assuming that this is a test database, so doesnt contain all fields (columns) or correct data. So i need to know if it is necessary to check if each field contains the old value of 2020 before I change it to 2021? mAnd if I did that, is there any chance that other data which should not be changed, also get updated??
'Loop through each column of table For i = 0 To rs.Fields.Count - 1
'Only update if field is not ID column and value is = Fra or empty If rs.Fields(i).Name <> "ID" Then If rs(i).Value = Fra Or Len(Trim(rs(i).Value)) = 0 Or IsNull(rs(i).Value) Then rs(i).Value = Til End If End If
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.
Det er blevet kaldt ”det største it-nedbrud i historien” og omkostningerne kan nemt løbe op i syv milliarder kroner: Men hvem skal betale for Crowdstrikes fejl?