473,402 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Transfer MS Word Form data to MS Access Tables

I'm trying to import data from the MS Word Form to multiple access tables in a one to many relationship.

The MS Word Form contained the applicant’s personal details (Table CustDetails) and the training sessions applied (Table Sessions).

With the help of the below article posted on Bytes, I managed to do it successfully.
https://bytes.com/topic/access/answers/773541-word-form-access-tables-data-transfer

However, I have other challenges.

The MS Word Form I used to collect data contained a table of records where the applicants need to enter information such as date, time and session names – information about the sessions they have applied. The users may apply for multiple sessions.

The MS Word Form I have designed has catered up to 10 sessions for the users to enter.

I have assigned simple content control names to the 10 sets of records to be collected.

Session Name - SessionName01 to SessionName10
Session Date - SessionDate01 to SessionDate10
Session Time - SessionTime01 to SessionTime10

The Tables and fields as follows:
1. CustDetails
a. [ID] - AutoNumber/Primary Key
b. [CoName]
c. [CustName]
d. [Phone]
e. [email]

2. Sessions
a. [SessionID] - AutoNumber/PrimaryKey
b. [ID] - LONG/Links to CustDetails.[ID] {MANY to 1}
c. [SessionName]
d. [SessionDate]
e. [SessionTime]

Currently, I am adding records to the Sessions table by duplicating the “.AddNew” statement for record 1 to 10 (in actual fact, the maximum sessions can go up to 20).

Expand|Select|Wrap|Line Numbers
  1. Dim CompanyName As String
  2. Dim CustomerName As String
  3. Dim Telephone As String
  4. Dim EmailAdd As String
  5. Dim SessionName01 As String
  6. Dim SessionName02 As String
  7. Dim SessionName03 As String
  8. Dim SessionName04 As String
  9. Dim SessionName05 As String
  10. Dim SessionDate01 As Date
  11. Dim SessionDate02 As Date
  12. Dim SessionDate03 As Date
  13. Dim SessionDate04 As Date
  14. Dim SessionDate05 As Date
  15. Dim SessionTime01 As Date
  16. Dim SessionTime02 As Date
  17. Dim SessionTime03 As Date
  18. Dim SessionTime04 As Date
  19. Dim SessionTime05 As Date
  20. Dim lngSessionID As Long
  21.  
  22. Set cnn = CurrentProject.Connection
  23.  
  24. rst.Open "CustDetails", cnn, adOpenKeyset, adLockOptimistic
  25. rstEvents.Open "Sesssions", cnn, adOpenKeyset, adLockOptimistic
  26.  
  27. ‘************************************************************
  28. ‘ add records to CustDetails table
  29. With rst
  30. .AddNew
  31.     .Fields("CoName") = CompanyName
  32.     .Fields("CustName") = CustomerName
  33.     .Fields("Phone") = Telephone
  34.     .Fields("Email") = EmailAdd
  35.  
  36.     rst.Update
  37. End With
  38.     rst.Requery
  39. rst.Close: Set rst = Nothing
  40.  
  41. ‘************************************************************
  42. ‘ add records to Sessions table
  43. lngSessionID = DLast("[ID]", "CustDetails")
  44.  
  45. With rstEvents
  46.  
  47. rstEvents.AddNew
  48. rstEvents.Fields("ID") = lngEventID
  49. rstEvents.Fields("SessionName") = SessionName01
  50. rstEvents.Fields("SessionDate") = SessionDate01
  51. rstEvents.Fields("SessionTime") = SessionTime01
  52. rstEvents.Update
  53.  
  54. ‘ repeating above statements for all remaining records from 02 through 10
  55. With rstEvents
  56. rstEvents.AddNew
  57. rstEvents.Fields("ID") = lngEventID
  58. rstEvents.Fields("SessionName") = SessionName02
  59. rstEvents.Fields("SessionDate") = SessionDate02
  60. rstEvents.Fields("SessionTime") = SessionTime02
  61. rstEvents.Update
  62.  
  63. With rstEvents
  64. rstEvents.AddNew
  65. rstEvents.Fields("ID") = lngEventID
  66. rstEvents.Fields("SessionName") = SessionName03
  67. rstEvents.Fields("SessionDate") = SessionDate03
  68. rstEvents.Fields("SessionTime") = SessionTime03
  69. rstEvents.Update
  70.  
  71. With rstEvents
  72. rstEvents.AddNew
  73. rstEvents.Fields("ID") = lngEventID
  74. rstEvents.Fields("SessionName") = SessionName04
  75. rstEvents.Fields("SessionDate") = SessionDate04
  76. rstEvents.Fields("SessionTime") = SessionTime04
  77. rstEvents.Update
  78.  
  79. With rstEvents
  80. rstEvents.AddNew
  81. rstEvents.Fields("ID") = lngEventID
  82. rstEvents.Fields("SessionName") = SessionName05
  83. rstEvents.Fields("SessionDate") = SessionDate05
  84. rstEvents.Fields("SessionTime") = SessionTime05
  85. rstEvents.Update
  86.  
  87. ‘ I will repeat the above another 5 to 10 times
  88.  
  89. End With
  90.  
  91.     rstEvents.Close: Set rstEvents = Nothing
  92.  
  93. doc.Close: Set doc = Nothing
  94. cnn.Close: Set cnn = Nothing
  95. appWord.Quit: Set appWord = Nothing
I wonder if there’s a simpler way to add new records to the Sessions table since the fields in the Word Form are all named as such that it ends with a 2-digit number with an increment of 1 (for example, SessionName01, SessionName02, 03..etc).


Also, is there a way to terminate the add records process once an empty field is detected (for example, the applicant has only applied for 3 sessions, so the 4th row onward are empty fields. The add records process should terminate immediately and end the data transfer.

Any help will be much appreciated.

Thank you.
Sep 16 '16 #1

✓ answered by zmbd

clarencelai The MS Word Form I used to collect data contained a table of records where the
See if this insight article will point you in the right direction.
home > topics > microsoft access / vba > insights > importing ms word tables into ms access tables using vba

Stevan even has a link to youtube showing this article in "applied theory" ;)

> Instead of a For..Next Loop, look at a Do_While or Do_Until loop

> If you are comfortable with "Late Binding" you would not need to set the references as given in the document/video. HOWEVER, I usually set the object library(s) during the development phase of the code as this allows me to use the inteli-sense and defined constants (i.e. vbYes actually has the value of 7) and the go back and declare the used constants and setup the late binding.

> Even it's close, but not just right, it will help us to help you zero in on the best solution.

2 1113
zmbd
5,501 Expert Mod 4TB
clarencelai The MS Word Form I used to collect data contained a table of records where the
See if this insight article will point you in the right direction.
home > topics > microsoft access / vba > insights > importing ms word tables into ms access tables using vba

Stevan even has a link to youtube showing this article in "applied theory" ;)

> Instead of a For..Next Loop, look at a Do_While or Do_Until loop

> If you are comfortable with "Late Binding" you would not need to set the references as given in the document/video. HOWEVER, I usually set the object library(s) during the development phase of the code as this allows me to use the inteli-sense and defined constants (i.e. vbYes actually has the value of 7) and the go back and declare the used constants and setup the late binding.

> Even it's close, but not just right, it will help us to help you zero in on the best solution.
Sep 24 '16 #2
Hi

I happened to bump into the aforementioned article shortly after I posted my questions. Took me a while to try the solution. Yes, it has helped to resolve the issue I have. Thanks!

Regards,
Clarence
Sep 30 '16 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

41
by: Ruby Tuesday | last post by:
Hi, I was wondering if expert can give me some lite to convert my word table into access database. Note: within each cell of my word table(s), some has multi-line data in it. In addition, there...
3
by: intl04 | last post by:
Is it possible to create a Word form as the data entry form for an Access database? I didn't see any reference to this possibility in my Access books, so I'm sorry if this is a question that is...
7
by: Mark Waser | last post by:
Hi all, I'm trying to post multipart/form-data to a web page but seem to have run into a wall. I'm familiar with RFC 1867 and have done this before (with AOLServer and Tcl) but just can't seem...
2
by: John | last post by:
Hi vs2005/sql server2004. I have created a simple winform app by dragging a table on a winform. I have used stored procedures for data access. I have the following questions; 1. Using the...
4
by: Kera | last post by:
Hi, I am working with a template document that has previously been created. I want to be able to populate the fields on the Userform on opening the Word template but before the form is shown. I...
1
by: burtell | last post by:
Previously, I wrote: I have designed an HTML form. The name of each element corresponds to a heading in an Access database on my computer. Is there a way for me to program the HTML form to send the...
13
by: BrokenMachine | last post by:
Hi there, I'm using Access 2003 and Word 2003 and I'm trying to import data from the word form to multiple access tables in a one to many relationship, but I can't seem to figure it out. I have...
6
by: Wesley Peace | last post by:
I hate to cross post, but I've gotten no answer yet on a problem I'm having with visual studio 2008. I've created a series of forms with controls to access a Access database tables. The...
3
by: JP Romano | last post by:
Hi - I'm putting together a status report summary for a team of about 15 based in the US (various places), London, Hong Kong, etc. The users have expressed interest in using a web form (data access...
4
Brilstern
by: Brilstern | last post by:
Many times we find ourselves moving from one format to another in the office space and sometimes moving data from one format to another can be a real pain in the butt. Automating these processes is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.