June 30, 2010 at 6:54 am
Private Sub Form_Load()
Dim cnThisConnect As ADODB.Connection
Dim rcdCompanies As ADODB.Recordset
Set cnThisConnect = CurrentProject.Connection
rcdCompanies.Open "tblCompanies", cnThisConnect, adOpenKeyset, adLockOptimistic
rcdCompanies.AddNew
rcdCompanies![CompanyName] = "Winthrop Brewing Companies"
rcdCompanies![Address] = "155 Riverside Ave."
rcdCompanies![City] = "Winthrop"
rcdCompanies![StateOrProvince] = "WA"
rcdCompanies![PostalCode] = "98862"
rcdCompanies![PhoneNumber] = "(509) 555-8100"
rcdCompanies.Update
End Sub
On Line 4, I am getting an Run Time Error 91. Please help! What should I do to make this code run.
July 2, 2010 at 10:32 am
ukarlink (6/30/2010)
Private Sub Form_Load()Dim cnThisConnect As ADODB.Connection
Dim rcdCompanies As ADODB.Recordset
Set cnThisConnect = CurrentProject.Connection
rcdCompanies.Open "tblCompanies", cnThisConnect, adOpenKeyset, adLockOptimistic
rcdCompanies.AddNew
rcdCompanies![CompanyName] = "Winthrop Brewing Companies"
rcdCompanies![Address] = "155 Riverside Ave."
rcdCompanies![City] = "Winthrop"
rcdCompanies![StateOrProvince] = "WA"
rcdCompanies![PostalCode] = "98862"
rcdCompanies![PhoneNumber] = "(509) 555-8100"
rcdCompanies.Update
End Sub
On Line 4, I am getting an Run Time Error 91. Please help! What should I do to make this code run.
-What file type are you working with .mdb or .adp?
-Do you have a reference set to the ADO object library?
-DAO is typically the preferred method of manipulating data when code in Access.
-Running an INSERT statement is actually faster than adding a record explicity.
-If you want the values to appear as the defaults in a new record use...
[Forms]![formName]![controlName] = [value]
July 2, 2010 at 10:59 am
google is your friend for Error 91:
ukarlink (6/30/2010)
Private Sub Form_Load()Dim cnThisConnect As NEW ADODB.Connection
cnThisConnect.ConnectionString = "data source=YourServer;initial catalog=SandBox;user id=DaveTheDeveloper;password=NotARealPassword;Trusted_Connection=False;Application Name=SSCExample.YouApplicationName.exe;"
cnThisConnect.Open
Dim rcdCompanies As NEW ADODB.Recordset
Set cnThisConnect = CurrentProject.Connection
rcdCompanies.Open "tblCompanies", cnThisConnect, adOpenKeyset, adLockOptimistic
rcdCompanies.AddNew
rcdCompanies![CompanyName] = "Winthrop Brewing Companies"
rcdCompanies![Address] = "155 Riverside Ave."
rcdCompanies![City] = "Winthrop"
rcdCompanies![StateOrProvince] = "WA"
rcdCompanies![PostalCode] = "98862"
rcdCompanies![PhoneNumber] = "(509) 555-8100"
rcdCompanies.Update
End Sub
On Line 4, I am getting an Run Time Error 91. Please help! What should I do to make this code run.
Lowell
July 2, 2010 at 11:54 am
Thanks to you guys! I was able to figure it out last night. I forgot to put "NEW" before ADODB.Recordset.
I appreciate your help. I am just new in writing VB code in Access.I know this is not a first time, certainly not the last time, I am going to ask for help. I hope you can help me out whenever you can. Thanks! Thanks!
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy