Results 1 to 2 of 2
  1. #1
    5 Star Lounger
    Join Date
    Jan 2001
    Posts
    1,119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Error in Code (2000)

    I am using the following code behind a Command button on a form:
    Private Sub CmdNewProj_Click()
    Dim strNewTask As String
    Dim rst As Recordset
    Dim lngNewProjID As Long, x As Integer

    strNewTask = InputBox("Enter the project name: ", _
    "New Project Name")

    If strNewTask = "" Then
    Exit Sub
    End If

    Set rst = CurrentDb.OpenRecordset("tblProjects")
    With rst
    .Edit
    .AddNew
    lngNewProjID = .Fields("lngProjectID")
    !lngcustomerID = Forms!frmProjects.lngcustomerID
    !strProjectName = strNewTask
    .Update
    .Close
    End With

    Set rst = Nothing
    Set rst = CurrentDb.OpenRecordset("tblTasks")

    With rst
    For x = 1 To 3
    .Edit
    .AddNew
    !lngProjectId = lngNewProjID
    Select Case x
    Case 1
    !strTaskType = "Design"
    Case 2
    !strTaskType = "Production"
    Case Else
    !strTaskType = "Quality Assurance"
    End Select
    .Update
    Next
    .Close
    End With

    Set rst = Nothing
    Me.Refresh

    DoCmd.GoToControl ("sbfProjects")
    DoCmd.GoToRecord , , acLast
    DoCmd.GoToControl ("qryDesign.dtmStartDate")

    End Sub

    For some reason it doesn't like ".Edit". Edit isn't in the drop down list but EditMode is. I tried that but it says it is used incorrectly. I checked the DOA 3.6 library in references. Does anyone know what I should put for .Edit?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Error in Code (2000)

    You don't need .Edit here (twice), since you are adding a new record with .AddNew.

    And I recommend explicitly declaring rst as a DAO recordset:

    Dim rst As DAO.Recordset.

    You probably also have a reference to the Microsoft ActiveX Data Objects 2.n Library. Since Recordset is also an object in that library, VBA gets confused.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •