RoyLiam
12-06-2006, 07:24 PM
I am working with a userform to prepopulate addressee details eg in a letter, and have been trying to get the useform to talk to an ODBC connection to get the relevant information (address etc) based on the unique key for the recipient which is stored with the addressees.
I can get the various information returned into a one row table using the DATABASE command, and if only one item/column of data eg name is asked for then it seems to return a string which is helpful. I have been trying to get it to do this look up when the code box is exited in the userform which it does, but I am struggling to get this text into the default text for the next input boxes in the form for the user to confirm, as I can only seem to get it to write the results into the current selection.range using something along these lines Private Sub code_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If code <> "" Then
ActiveDocument.Bookmarks("to").Select
Selection.Range.InsertDatabase Format:=0, Style:=191, LinkToSource:=False, _
Connection:= _
"DSN=clients;Driver=Firebird/InterBase(r) driver;Dbname=srv01:e:\ibdata\livev6.fdb;CHARSET=NONE;PWD=123;UID=ABRO" _
, SQLStatement:= _
"SELECT ENTITY.EN_NAME FROM ENTITY ENTITY WHERE (ENTITY.EN_KEY='" & code & "')" _
& "", PasswordDocument:="", PasswordTemplate:="", WritePasswordDocument _
:="", WritePasswordTemplate:="", DataSource:="", From:=-1, to:=-1, _
IncludeFields:=False
faxto.Text = Selection.Range ' this doesnt work as the insertdatabase function writes to the right of the bookmark
ActiveDocument.Bookmarks.Add "to", Selection.Range
End If
End Sub
I think I am going about this the wrong way and either there is a simple way of returning all of the 5 or 6 values into an array which can then be called upon for the relevant bits of it to populate the userform, after all if you request more than one at a time it returns them into a one row table format which feels like it should be close to an array format. Is it possible to return this straight into an array or do i need to return it into the blank document and then use a function to suck it into an array to then populate the userform for the users confirmation of the data before generating the letter.
Alternatively if the information needs to be called one by one then the insertdatbase functions seeme to be a bit rich each time and i wonder if there is a better command or way of doing this.
Has anyone looked at this recently, or is able to help in returning the database table into eg an array?
Any help is much appreciated
RoyLiam
I can get the various information returned into a one row table using the DATABASE command, and if only one item/column of data eg name is asked for then it seems to return a string which is helpful. I have been trying to get it to do this look up when the code box is exited in the userform which it does, but I am struggling to get this text into the default text for the next input boxes in the form for the user to confirm, as I can only seem to get it to write the results into the current selection.range using something along these lines Private Sub code_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If code <> "" Then
ActiveDocument.Bookmarks("to").Select
Selection.Range.InsertDatabase Format:=0, Style:=191, LinkToSource:=False, _
Connection:= _
"DSN=clients;Driver=Firebird/InterBase(r) driver;Dbname=srv01:e:\ibdata\livev6.fdb;CHARSET=NONE;PWD=123;UID=ABRO" _
, SQLStatement:= _
"SELECT ENTITY.EN_NAME FROM ENTITY ENTITY WHERE (ENTITY.EN_KEY='" & code & "')" _
& "", PasswordDocument:="", PasswordTemplate:="", WritePasswordDocument _
:="", WritePasswordTemplate:="", DataSource:="", From:=-1, to:=-1, _
IncludeFields:=False
faxto.Text = Selection.Range ' this doesnt work as the insertdatabase function writes to the right of the bookmark
ActiveDocument.Bookmarks.Add "to", Selection.Range
End If
End Sub
I think I am going about this the wrong way and either there is a simple way of returning all of the 5 or 6 values into an array which can then be called upon for the relevant bits of it to populate the userform, after all if you request more than one at a time it returns them into a one row table format which feels like it should be close to an array format. Is it possible to return this straight into an array or do i need to return it into the blank document and then use a function to suck it into an array to then populate the userform for the users confirmation of the data before generating the letter.
Alternatively if the information needs to be called one by one then the insertdatbase functions seeme to be a bit rich each time and i wonder if there is a better command or way of doing this.
Has anyone looked at this recently, or is able to help in returning the database table into eg an array?
Any help is much appreciated
RoyLiam