Run Time Error 91

  • 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.

  • 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]

  • 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


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • 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