|
-
Oct 31st, 2005, 10:48 AM
#1
Thread Starter
Fanatic Member
Rusty SQL Statement
VB Code:
Private Sub DatabaseM_Click()
Dim ADOCn As ADODB.Connection
Dim rsValues As ADODB.Recordset
Dim ConnString As String
ConnString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & CommonDialog1.FileName & ";" & _
"Persist Security Info=False"
Set ADOCn = New ADODB.Connection
ADOCn.ConnectionString = ConnString
ADOCn.Open
Set rsValues = New ADODB.Recordset
rsValues.Open "SELECT * FROM Overview", ADOCn, adOpenKeyset, adLockOptimistic, adCmdText
With rsValues
.AddNew
.Fields("ProjName").Value = ProjNameT.Text
.Fields("OilComp").Value = OilCoT.Text
.Fields("GeoCon").Value = GeoT.Text
.Fields("SurveyCon").Value = SurvT.Text
.Fields("DrillCon").Value = DrillT.Text
.Fields("Total").Value = AcresT.Text
.Fields("TodDate").Value = DateT.Text
.Fields("StartDate").Value = StartT.Text
.Update
End With
ProjNameT.Text = vbNullString
OilCoT.Text = vbNullString
GeoT.Text = vbNullString
SurvT.Text = vbNullString
DrillT.Text = vbNullString
AcresT.Text = vbNullString
DateT.Text = vbNullString
StartT.Text = vbNullString
rsValues.MoveFirst
End Sub
And also, Say that i have 70 textboxes instead of 9, is there anyway that i could use ADO without typing out all 70 textboxes and all 70 fields?
-
Nov 1st, 2005, 06:13 AM
#2
Re: Rusty SQL Statement
 Originally Posted by cid
And also, Say that i have 70 textboxes instead of 9, is there anyway that i could use ADO without typing out all 70 textboxes and all 70 fields? 
I dont think so, you'll just have to type away :-/
as for the code, remmber to set your connection and recordset = nothing when finished 
Pino
-
Nov 1st, 2005, 10:15 AM
#3
Re: Rusty SQL Statement
 Originally Posted by cid
And also, Say that i have 70 textboxes instead of 9, is there anyway that i could use ADO without typing out all 70 textboxes and all 70 fields?
Yes, assuming the fields in your recordset are in the same order of the Textbox Array:
VB Code:
Set rsValues = New ADODB.Recordset
rsValues.Open "SELECT * FROM Overview", ADOCn, adOpenKeyset, adLockOptimistic, adCmdText
With rsValues
.AddNew
With .Fields
For a = 1 To .Count - 1
.Value = Text1.Item(a).Text & ""
Next a
End With
.Update
End With
Last edited by Mark Gambo; Nov 1st, 2005 at 11:42 AM.
Regards,
Mark
Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."
-
Nov 1st, 2005, 11:39 AM
#4
Re: Rusty SQL Statement
you didnt say array :grr:
Pino
-
Nov 30th, 2005, 03:39 PM
#5
Fanatic Member
Re: Rusty SQL Statement
Sure, loop through a control collection specifying that they be text boxes. Then if you either A) Name the text box as the field name in the Db, or B) set a property each control has in VB which can just store data you can use.. I forget the property name... then you can do...
VB Code:
Dim CTL as Control
For Each CTL in Controls
'Some test to make sure it is a textbox
rs.fields(CTL.Name).Value=CTL.Text
Next CTL
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|