Renvoi de l'index d'un champ dans un jeu d'loggings

J'ai l'object suivant du jeu d'loggings qui est généré par le code suivant

Private Sub GetID_Click() 'first find max id on sheet; used for if no ID is found on sheet Dim myRange As Range Dim maxIdOnSheet As Long Dim clientSheet As Worksheet Set clientSheet = Sheets("Client Codes") Set myRange = clientSheet.Range("A1:A1048576") maxIdOnSheet = WorksheetFunction.max(myRange) + 1 'set up connections with Nina's housing database Dim cmd As New ADODB.Command Dim conn As New ADODB.Connection Dim rs As New ADODB.Recordset Dim strConn As Ssortingng Dim strSQL As Ssortingng Dim IDdb As Long Dim IDwb As Long 'connection ssortingng strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\db\path\here\db.accdb; Persist Security Info=False" 'open connection database conn.Open strConn 'sql statement strSQL = "SELECT * FROM Clients WHERE (((Clients.FirstName)='" & FirstName.Value & "') AND ((Clients.LastName)='" & LastName.Value & "'));" 'open connection with the recordset rs.Open strSQL, conn, adOpenDynamic, adLockOptimistic 'use the late-bound application match method to find out where the firstname and lastname values are in the worksheet, if found Dim first As Long Dim last As Long Dim foundWB As Boolean Dim foundDB As Boolean foundWB = False foundDB = False Dim base As Long Dim curRow As Long base = 1 'First check to make sure if both values are in the worksheet If Not IsError(Application.Match(FirstName.Value, Range("c" & base & ":c1048576"), False)) And Not IsError((Application.Match(LastName.Value, Range("b" & base & ":b1048576"), False))) Then 'if it is in the worksheet, find where it is While found = False first = Application.Match(FirstName.Value, Range("c" & base & ":c1048576"), False) last = Application.Match(LastName.Value, Range("b" & base & ":b1048576"), False) If first = last Then foundWS = True curRow = curRow + first IDwb = Cells(curRow, 1) Else If first < last Then base = first + 1 curRow = curRow + first ElseIf last < first Then base = last + 1 curRow = curRow + last End If End If Wend Else 'if its not in the WS, it is now the highest +1 IDwb = WorksheetFunction.max(Range("a1:a1048576")) + 1 End If 'find if its in the database If rs.EOF Then 'if its not in the database, find the highest number and add 1 rs.Close strSQL = "SELECT MAX(Clients.[Client ID]) FROM Clients;" rs.Open strSQL, conn, adOpenDynamic, adLockOptimistic IDdb = rs.Fields(0) + 1 MsgBox (rs.Properties.Item("Address")) Else 'if it is, find the first column IDdb = rs.Fields(0) foundDB = True MsgBox (rs.Properties.Item("Address")) End If If foundWB = True Then ClientID.Value = IDwb ElseIf foundDB = True Then ClientID.Value = IDdb Else If IDdb > IDwb Then ClientID.Value = IDdb ElseIf IDwb > IDdb Then ClientID.Value = IDwb Else ClientID.Value = IDwb End If End If End Sub 

J'ai deux sources de données: la feuille de calcul sur laquelle cette macro est située dans Excel et une database d'access. Je dois saisir datatables du client et lui atsortingbuer un code spécifique. Le code fonctionne avec succès.

Cependant, ce que je veux faire, c'est remplir un formulaire d'user basé sur ce code qui est reçu. Le code ci-dessus a réussi à interroger la database et peut get l'ID du client, mais je veux aussi des choses comme l'adresse, la ville, l'état, le zip, le revenu du ménage, qui est stocké dans le DB à get de la requête. Si je faisais cela dans ssortingctement excel, j'utiliserais une déclaration de correspondance et, si c'est ssortingctement à travers l'access, une requête SQL. Mais j'essaie d'exécuter cette requête à la fois d'une feuille de calcul Excel et d'une database d'access, ou dans le même code. Cela nécessite la configuration d'un object jeu d'loggings: la documentation se trouve ici http://www.w3schools.com/asp/ado_ref_recordset.asp

et voici https://msdn.microsoft.com/en-us/library/ms675841(v=vs.85).aspx

Je sais que je peux get l'information en disant quelque chose comme name = rs.fields (1), address = rs.fields (4), city = rs.fields (5)

etc. Mais je préférerais avoir l'indice de façon dynamic, car je ne suis pas sûr que les personnes avec qui je travaille modifient la database (probablement pas, mais mieux que désolé), alors s'ils ajoutent des colonnes que je souhaiterais pour la formule pour être stable.

Alors, comment puis-je find dynamicment l'index d'un champ spécifique dans un object jeu d'loggings? Disons si le champ "Adresse" pourrait être l'index 4,5,6,7, jusqu'à chaque fois.