AboutRichard Rost Expertise I can answer any questions pertaining to Microsoft Visual Basic 6.0, Microsoft Access VBA, and the Visual Basic Language in general. I do NOT use VB.NET or VB 2005/08 much yet, so don't ask me any questions specific to those. Also, please feel free to check the Tips & Tricks section of my web site for VB tips.
Education/Credentials I am a self-taught VB expert. I have been building software for clients since the early 90s (and on my own since I was a child). You can see a sample of my Tutorials on my web site at 599CD.com
Expert: Richard Rost Date: 7/10/2008 Subject: vb code
Question
Hi,
I am a beginner in Vb6 with access 2000 coding i am designing a project for the diabled people.I am trying to use multiple forms for the data entry for a single access table which i create in the first form.i use one adodc connection only i cant give the record source at design time.
my code goes like this
Option Explicit
Dim cnn As New ADODB.Connection, rec As ADODB.Recordset
Dim a As String
Private Sub Command1_Click()
rec.Open ("select * from tableName a ")
rec.AddNew
'you have used text1 to create the tablename
rec.Fields(0) = Val(text2)
rec.Fields(1) = Val(text3)
rec.Fields(2) = Val(text4)
'.. and so on for all fields
rec.Update
If Not rec.EOF Then rec.MoveNext
rec.Close
End Sub
Private Sub Form_click()
Set cnn = New ADODB.Connection
cnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:Documents and SettingsRavindraMy DocumentsTest_1.mdb;Persist Security Info=False"
Set rec = New ADODB.Recordset
cnn.Open
'for the creation of table.
a = Text1 ' or inputbox("enter tablename")
cnn.Execute "CREATE TABLE " & a & " (id integer, intensity integer,Tim integer)"
End Sub
Private Sub Form_Unload(Cancel As Integer)
cnn.Close
Set cnn = Nothing
End Sub
BUT SOME ERROR CN.OPEN
Answer If you need to specify the table to open at RunTime then just put it in a variable and say:
rec.Open ("select * from " & TABLENAME)
Let me know if you have any other questions or comments.
P.P.S. I volunteer my time at AllExperts to help people, and I get a LOT of questions, so I can't take an hour to answer each question. If you need more DETAILED HELP, come to my TechHelp web site at http://www.599cd.com/TechHelp/AllExperts and I'll take as much time as you need to answer your question.