Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie needs help with Add records to recordset

Status
Not open for further replies.

twd8363

Technical User
May 2, 2001
1
US
HELP!!!

I am trying to add new record to a record set based on a SQL statement. I am using a select statement with dbopendynaset recordset type. I am attempting to use the following on the form.
1. Combo box to obtain a list of quotes on the main form.
2. Combo box to select customer information on a tabbed conctainer.

The bottom line is I can get the recordset open and display the number of records but when I go to add a record i get totally lost. I was toying with the Idea of creating an identical form for creating the new quote and then after the save is complete bring up the sql based form.

I am sure I have you all confused. Any help wqould be great.

Thanks
Tom
 
Not 100% certain what you're trying to do, but the following is generic for adding new records to recordsets:

myRs.AddNew

then set the fields in the recordset to what you want them to be, then

myRs.Update

where myRs is your recordset.

HTH

Muttley


 
What exadctly is the syntax to set the fields to what you want them to be? For example, will the following work?

myRS.AddNew
MyField1=abc
MyField2=def
myRS.Update

Do I have to declare MyField1, etc? I am trying to avoid setting the control source for my textboxes and I want to be able to do something like:

Private Sub cmdSave_Click()
myRS.AddNew
MyField1 = txtMyField1.text
MyField2 = txtMyField2.text
myRS.Update
End Sub
 
Nevermind... I tried it and it works.. My table has 3 fields in it and when I use the following code to update my table, I get an error message on the last line, saying that the SalesDate cannot be null and that it requires a value. It looks like I have given it a value. Any ideas? When I leave off that last line, the code runs fine. It just seems like a good idea to update the recordset after I add something to it.

Me.Recordset.AddNew
Customer_ID = 1
Amount = 40000
SalesDate = #8/1/2001#
Me.Recordset.Update
 
When you are executing your code, what value does your SalesDate object hold? If you're not sure how to do this, either hold your cursor over the SalesDate text, or add the following line to your code before the update statement:

debug.print SalesDate

You can then view the properties of this field in the debug window.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top