-
December 18th, 2007, 10:41 AM
#1
Help with database
I am really stuck right now. How do you start with an empty recordset and the program add a record when the program launches. I have tried the simple:
Data1.RecordSet.AddNew, but I get 'Error 91'.
I would really appreciate if someone could help me with this.
Thx!!!
Perfection is flaw.....
-
December 18th, 2007, 11:06 AM
#2
Re: Help with database
Post your code. Bound controls are harder to work with
-
December 18th, 2007, 08:41 PM
#3
Re: Help with database
I would post my code but I don't really have any working code. I would simply like to know how to have the program start a new record on runtime. My recordset will be empty when the program first loads.
Also, I was wondering if there is any good source out there where I could full instructions on how access databases work.
Thx!!
Perfection is flaw.....
-
December 18th, 2007, 09:19 PM
#4
Re: Help with database
To insert new record, you can try to use SQL statement
-
December 18th, 2007, 09:55 PM
#5
Re: Help with database
You should create the table first in Access, but you don't need to add records.
You could delete all records when the program starts as well.
Read about SQL
-
December 20th, 2007, 07:31 AM
#6
-
December 21st, 2007, 02:01 AM
#7
Re: Help with database
i think the code below is a good one to start with, ADO (http://www.w3schools.com/ado/ado_intro.asp).. just read the comments to know what the code is doing..
Code:
Option Explicit
Dim m_cn As ADODB.Connection
Dim m_rs As ADODB.Recordset
' open connection/recordset
Private Sub Form_Load()
Set m_cn = New ADODB.Connection
m_cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=<MDB filename>;"
Set m_rs = New ADODB.Recordset
m_rs.Open "SELECT * FROM <table name>", m_cn, adOpenKeyset, adLockOptimistic
End Sub
' close connection/recordset
Private Sub Form_Unload(Cancel As Integer)
m_rs.Close
Set m_rs = Nothing
m_cn.Close
Set m_cn = Nothing
End Sub
' add one record
Private Sub Command1_Click()
m_rs.AddNew
m_rs("field1").Value = "value1"
m_rs("field2").Value = "value2"
m_rs("fieldN").Value = "valueN"
m_rs.Update
End Sub
Last edited by Thread1; December 21st, 2007 at 02:03 AM.
Busy
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
|