You are going to have to open (or create) a document, then retrieve that value. Once the document is open it can accept whatever value you pass to it, within legitimate procedures of course. However, I do not know of a way to pass a value to Word BEFORE loading it.
So open the first document.
Query the database for the first record.
Do whatever it is your are doing (you do not say what that is).
Save that document.
Add a new one, get the next record and do what ever it is your are doing.
and so on.
This is from Word.
On the other hand, if you are doing (what ever it is you are doing...which you do not say) it from outside of Word, then you have to create an instance of Word, then process.
Can't really say much else, as "construct a document for each record into a table" still does not say a lot.
Further, it seems the actual problem is getting the primary key from the html(aspx) page, correct? So it is, in fact, THAT value you are trying to get into Word, correct?
You do really have to clearly spell out things, as we are not mind readers.
If the problem is getting data (your primary key) from a web page....say so. Say if that is a file on a local machine, on a local network, out there on a remote web server.
Do you know how to get the value from that page programatically? If so, do it from inside Word. Then in fact you are not "passing" the argument to Word - Word (and VBA) is "getting" the argument.
Since I, for one, am still not clear what the situation is, or what you are trying to do, but it seems somewhat related to getting information from a web page, I suggest you look up some information on sending a WinHTTPRequest. This uses the WinHTTP.DLL library, which MUST be referenced.
I am still unclear, the primary key is on a HTML page, but you have the other values in your SQL DB?
Gerry