View Full Version : Using data inserted in a textbox of a form in VBA


Leen
05-03-2007, 05:22 AM
Hi!

I made a form in which the user of the form needs to enter the name of a table and its datasource. Once he has written this, I want to run a macro that inserts that table into Access

For that macro their is no problem:

PathSource = "D:\Leen"
NameInput = "railway_line_pune.dbf"

DoCmd.TransferDatabase acImport, "dBASE IV", PathSource, acTable, NameInput, "Railways_KNVL", False

But, when a user enters a name in a textbox of a form, I want, by using for example the "AfterUpdate Event" - code builder - to write code that puts the inserted name by the user as PathSource. Can someone help?

I should be something like:

Private Sub Source_AfterUpdate()
Dim PathSource As String
Set PathSource = the text entered by the user in the textbox of the form?
End Sub

Thanks a lot!
Leen

boblarson
05-03-2007, 05:28 AM
First of all it would be:


Private Sub Source_AfterUpdate()
Dim PathSource As String
PathSource = Forms!YourFormNameHere.YourTextBoxNameHere
End Sub

But, if you declare the string PathSource in the AfterUpdate event by using Dim PathSource As String, then it will not be available to you outside of that event.

What you want is to declare it in the General Declarations Section of a STANDARD module, not a form module and use:

Public PathSource As String

so it will become available to you from anywhere in your code.