• Write HTML Table data db

    Author
    Topic
    #385203

    This might be difficult. I wrote some .asp code to dynamically generate an HTML table with input boxes for n number of rows via a textbox. You click on the submit button and get a new .asp page with the table ready for input. Now, what I want to do is write each row to a Access table.

    Here’s the skinny: specify the number of Recipients (ie number of rows) – this goes to .asp code that generates a table whose items i can list out like so:


    1 RecipientAge1 = 1
    2 RecipientGender1 = Male
    3 Ethnicity1 = Black
    4 InsuranceStatus1 = Medicaid
    5 RecipientAge2 = 2
    6 RecipientGender2 = Female
    7 Ethnicity2 = White
    8 InsuranceStatus2 = Medicare

    There are, in this case, 2 rows and the Name in the first column and the Value in the second. the names increment based on 0 to N from the input box on the referring form. If I take out the increment then I get a single Name with multiple values, comma-seperated. From there I get puzzled. It’s not obvious to me how you could ‘page thru’ each rown and assign values to a table in Access — I could just run a insert the table in question but in order to make sure the hidden field names match I’d end up with comma-seperate values in one row (sets of values for each column) rather than multiple rows.

    Any suggestions??

    Viewing 0 reply threads
    Author
    Replies
    • #663580

      Hi Steve,

      As with most issues, there are many ways to attack this one. I would stay away from Comma-separated values here. I think you can do it much easier by simply passing form variables and working with code loops. Here’s the basic idea:

      Page 1) Receive the number of rows from the user (let’s call it lngRows)
      Page 2) Create a table based on the desired number of rows (using a code loop). Since you only plan to collect 4 fields (columns), I would suggest using numbers for the fields (1-4) and numbers for the rows. I typically use an object name like 1_1 (field_row). That makes it easy when processing the items in the last page. Let’s say your user enters 3 for the number of rows. (Be sure to pass lngRows as a hidden form variable.) Your text boxes should be generated like so:

      Recipient Age Recipient Gender Ethnicity Insurance Status
      1. (1_1) (1_2) (1_3) (1_4)
      2. (2_1) (2_2) (2_3) (2_4)
      3. (3_1) (3_2) (3_3) (3_4)
      4. (4_1) (4_2) (4_3) (4_4)

      Page 3) Here’s where it gets fun. Grab the lngRows variable which should be passed through the form. You’ll want to use a loop to collect the values as such:
      (assume rst is the opened recordset object and lngRows is the row count)

      Dim X
      For X = 1 to lngRows
      rst.AddNew
      rst(“RecipientAge”) = Request.Form(X & “_1”)
      rst(“RecipientGender”) = Request.Form(X & “_2”)
      rst(“Ethnicity”) = Request.Form(X & “_3”)
      rst(“InsuranceStatus”) = Request.Form(X & “_4”)
      rst.Update
      Next

      rst.Close
      set rst = nothing

      Hope this helps!

      • #663759

        worked perfectly! thanks. cheers

        don’t know why but i do enjoy this sort of thing. must have gotten dropped on my head when young… bash

    Viewing 0 reply threads
    Reply To: Write HTML Table data db

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: