inserting record into existing table

ds_8805

Registered User.
Local time
Yesterday, 16:41
Joined
Jan 21, 2010
Messages
70
Hello Everyone! I have an form. The function of this form is that when the user clicks on the save button after entering some data, it should be able to go and store into the table. Does anyone have any idea how I can insert new record into a table through vba coding?

Thanks for any help :)
 
here is what i have managed to come up with

Private Sub Back_Click()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb()
Set rs = db.OpenRecordset("Info of payee", dbOpenDynaset)
'Me.PayeeID = " "
rs.AddNew
![PayeeName] = Me.PayeeName
![PayeeAddress] = Me.PayeeAddress
![PostalCode] = Me.PostalCode
![TypeOfPayee] = Me.TypeOfPayee
'!TagNumber = Me.TagNumber
rs.update
rs.Close
Set rs = Nothing
Set db = Nothing
End Sub

however i am still getting error saying unqualified reference.
someone pls help! :)
 
Why VBA? Are you disallowed from using bound forms? Wouldn't it be easier to use a non-Access platform if you don't use bound forms?

The error you are experiencing has no meaning. Where does it say it? When? Is there a line high-lighted? Is there an error number?

I'm guessing you'll want to put a qualifier around your table or query name, like this:
Code:
Set rs = db.OpenRecordset("[Info of payee]", dbOpenDynaset)
 
Hey the error is still there. when i try to run it, it says compile error " invalid or unqualified ref". It highlights this ![PayeeName] .

The thing is my table has the following columns : PayeeID,AccountNo, PayeeName, Payeeadd, type of payee. the payeeid column is an autonumber.
I have used a similar thing elsewhere in my project and it works perfectly fine. That is why I decided to use smthg similar to for this as well.

I would really like to know what is causing this to occur.

What is bound forms? How do we use that?
 
Its the ! (bang) that's doing it. Use rs("FieldName") = Me.TextBox.
 
so it is saying that you dont have a field called [payeename] in your table

(or maybe that you dont have a control called payeename on your form)

check these out - maybe you put an extra space in the table definition


============
and of course dcrake has spotted the real issue
its either

rs!payeename = whatever
rs("payeename") = whatever

or

WITH rs
!payeename = whatever
END WITH
 
hey thanks for ur help guys. I tried putting in the with block and it works now. However i have another problem. I got another error msg which is

"The changes you requested to the table were not successful because they would create
duplicate values in the index, primary key or relationship. Change the data in the field or fields that contain duplicate data, remove the index , or redefine the index to permit duplicate
entries and try again. "

The thing is I cannot allow duplicate values. The payee id is the primary key and its autonumber. So how to solve the problem and ensure that all payees have an unique id?

Thanks for ur help :D
 

Users who are viewing this thread

Back
Top Bottom