Export data from VBA Userform to Access?

mmartinez13

New Member
Joined
Sep 1, 2011
Messages
21
How do I export data from a VBA Userform to Access? I have 7 columns and 8 rows, I would like to have these exported to Access in order from my userform.

Thanks in advance for all the help.
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
I'm confused, do you have this information on a worksheet? Or you have a userform that's made to look like a worksheet?
 
Upvote 0
Sorry to hear that. Do you already have a table in Access, or do you need to create a new one?
 
Upvote 0
I do not have a table in Access yet, so, I will need to create a new one.

I do have a worksheet also. I was wanting to use the userform for operator use. I can use the worksheet if needed.
 
Upvote 0
Without more information about the structure of the userform and the table that is needed, it will be difficult to write the appropriate code. Do you already have code that collects user input from the userform and puts it into variables?

If the table only needed to be created once, I would just create it manually in Access. Otherwise I would use ADO to execute a SQL statement against the DB to create the table as often as needed.

Either way, I would use ADO to open the database and insert the data from the userform into the fields of the table.

This procedure could be used to create the table (assumes Access 2003):

Code:
Sub ExecuteQuery(databasePath As String, sqlQuery As String)
Dim conn As Object ' ADODB.Connection
 
  Set conn = CreateObject("ADODB.Connection")
  conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source=" & databasePath & ";"
  conn.Execute sqlQuery
End Sub

Source: http://www.vb-helper.com/howto_ado_create_table.html

The same procedure could be used to populate the table with information from your userform.
 
Upvote 0

Forum statistics

Threads
1,224,582
Messages
6,179,670
Members
452,936
Latest member
anamikabhargaw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top