Problem Moving To Next Record

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MindBender77
    New Member
    • Jul 2007
    • 233

    Problem Moving To Next Record

    Hello All,
    I believe I have a simple problem but, can't seem to find a easy solution. First, I developed a form (popup) with 2 combo boxes and a submit button.

    When I make a choice from both cbo and click submit, a form corresponding to the entries are displayed. However, when the form tries to open, I get an error stating "Can Not Go To Specified Record in Design View."

    I'm using the this code to open the form.
    [code=vb]
    DoCmd.OpenForm "FormName", acNormal
    [/code]

    Any Help Will Be Appreciated,
    Bender

    PS - If I open the form directly, I do not get the error.
  • missinglinq
    Recognized Expert Specialist
    • Nov 2006
    • 3533

    #2
    Originally posted by MindBender77
    When I make a choice from both cbo and click submit, a form corresponding to the entries are displayed.
    Are you, in fact, asking Access to go to a particular record when the form opens, and if so, how?

    There's obviously nothing wrong with the code you've posted, but neither does it demonstrate how the values selected from your comboboxes are being assigned to this process, and we need to see that code.

    Linq ;0)>

    Comment

    • MindBender77
      New Member
      • Jul 2007
      • 233

      #3
      Basically the code for the Submit button which opens the form is:
      X and Y are String data types
      Code:
      if ComboBox1 = X and cbo2 = Y then
      docmd.openform "formname", acNormal
      end if
      Then here is the code that is produces the error. Note, it works as it should when opening the form directly, without the comboboxes.
      [code=vb]
      Dim date_cleaned, Cell
      Dim cleanings
      Dim PDate As Date

      PDate = DateValue(Forma t(Now, "mm/dd/yyyy"))
      Cell = txt_cell


      Call last_cleaned 'Runs An Append Query. Appending Last Cleaned Date and count of cleanings to table "tbl_Last_Date_ Cleaned_91-1"

      cleanings = DLookup("[Number of Cleanings]", "tbl_Last_Date_ Cleaned_91-1")
      date_cleaned = DLookup("[LastOfDate]", "tbl_Last_Date_ Cleaned_91-1")

      If txt_frequency = "Twice a Shift" And cleanings <= 1 And date_cleaned <= PDate Then
      DoCmd.OpenQuery ("qry_Delete_La st_Date_Cleaned _91-1")
      Exit Sub
      Else
      DoCmd.GoToRecor d , , acNext 'This Is Where The Error Occurs
      DoCmd.OpenQuery ("qry_Delete_La st_Date_Cleaned _91-1")
      End If
      [/code]

      Bender

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32661

        #4
        Frustratingly, probably the most important piece of information is what you left out :D

        Where is the second batch of code to be found and what is the procedure called (I suspect it may be the Form_Open() procedure in the form's own module)?

        Comment

        • MindBender77
          New Member
          • Jul 2007
          • 233

          #5
          I didn't think the OnOpen was causing the issue but, then again, I'm the one stumped on this so any help would be tremendous:

          Bender

          [code=vb]
          Private Sub Form_Open(Cance l As Integer)
          Dim current_day


          DoCmd.RunMacro ("Minimize") 'Minimizes the Access window allowing just the form to be visible
          current_day = Format(Weekday( Now, vbSunday), "dddd")


          If current_day = "Sunday" Then
          ck_sunday.Enabl ed = True
          ck_monday.Enabl ed = False
          ck_tuesday.Enab led = False
          ck_wednesday.En abled = False
          ck_thursday.Ena bled = False
          ck_friday.Enabl ed = False
          ck_sunday = 0


          ElseIf current_day = "Monday" Then
          ck_sunday.Enabl ed = False
          ck_monday.Enabl ed = True
          ck_tuesday.Enab led = False
          ck_wednesday.En abled = False
          ck_thursday.Ena bled = False
          ck_friday.Enabl ed = False
          ck_monday = 0


          ElseIf current_day = "Tuesday" Then
          ck_sunday.Enabl ed = False
          ck_monday.Enabl ed = False
          ck_tuesday.Enab led = True
          ck_wednesday.En abled = False
          ck_thursday.Ena bled = False
          ck_friday.Enabl ed = False
          ck_tuesday = 0

          ElseIf current_day = "Wednesday" Then
          ck_sunday.Enabl ed = False
          ck_monday.Enabl ed = False
          ck_tuesday.Enab led = False
          ck_wednesday.En abled = True
          ck_thursday.Ena bled = False
          ck_friday.Enabl ed = False
          ck_wednesday = 0

          ElseIf current_day = "Thursday" Then
          ck_sunday.Enabl ed = False
          ck_monday.Enabl ed = False
          ck_tuesday.Enab led = False
          ck_wednesday.En abled = False
          ck_thursday.Ena bled = True
          ck_friday.Enabl ed = False
          ck_thursday = 0

          ElseIf current_day = "Friday" Then
          ck_sunday.Enabl ed = False
          ck_monday.Enabl ed = False
          ck_tuesday.Enab led = False
          ck_wednesday.En abled = False
          ck_thursday.Ena bled = False
          ck_friday.Enabl ed = True
          ck_friday = 0

          ElseIf current_day = "Saturday" Then
          ck_sunday.Enabl ed = False
          ck_monday.Enabl ed = False
          ck_tuesday.Enab led = False
          ck_wednesday.En abled = False
          ck_friday.Enabl ed = False
          ck_saturday.Ena bled = True
          ck_saturday = 0
          End If

          End Sub
          [/code]

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32661

            #6
            Bender, I suspect, in effect, it's not (though I have provided an alternative that's a little shorter).

            What I was asking for (sorry I didn't make this clearer) was the information that showed how the second block of code in your post (#3) fitted into the situation (how is it executed).

            What you provided was fine, but I couldn't see what I needed in it so I asked for some extra info. Clearly you were careful not to overload the post with useless info which I can only applaud, but sometimes useful bits are missed out too. It's a call you have to make, and I far prefer posters who make that call and maybe get it a little wrong to those who don't even get the concept.
            [code=vb]Private Sub Form_Open(Cance l As Integer)
            Dim Current_Day As String
            Dim ctlMe As Control

            DoCmd.RunMacro ("Minimize") 'Minimizes the Access window allowing just the form to be visible
            Current_Day = Format(Date(), "dddd")

            ck_Sunday.Enabl ed = False
            ck_Monday.Enabl ed = False
            ck_Tuesday.Enab led = False
            ck_Wednesday.En abled = False
            ck_Thursday.Ena bled = False
            ck_Friday.Enabl ed = False
            ck_Saturday.Ena bled = False

            For Each ctlMe In Me.Controls
            If Mid(ctlMe.Name, 4) = Current_Day Then
            ctlMe.Enabled = True
            ctlMe = 0
            End If
            Next ctlMe

            End Sub[/code]
            In your code ck_Saturday was omitted from most groups (and ck_Thursday was omitted for the Saturday group). I assumed this was an oversight and coded accordingly.

            Comment

            • MindBender77
              New Member
              • Jul 2007
              • 233

              #7
              I am uncertain on the usage of "For Each" and I seem to stay away from it. As you illustrated, I definitely have to build up my confidence in its functions.

              As for the code I left out: At the end of the OnOpen event, there is a call to a sub. Here is its code. Note: The call frequency_check _daily is from Post #3.
              [code=vb]
              Private Sub Aggitator()
              Dim msg, style, title, response
              Dim Unit, Cell

              Unit = txt_unit
              Cell = txt_cell

              If txt_frequency = "" Or IsNull(txt_freq uency) = True Or IsNull(Cell) = True Then
              msg = "There Is Currently No Cell That Needs Maintenance At This Time."
              style = vbOKOnly + vbInformation + defaultbutton2
              title = "Plus Bank Maintenance"
              response = MsgBox(msg, style, title)
              ck_sunday.Enabl ed = False
              ck_monday.Enabl ed = False
              ck_tuesday.Enab led = False
              ck_wednesday.En abled = False
              ck_thursday.Ena bled = False
              ck_friday.Enabl ed = False
              Else

              If txt_frequency = "Twice a Shift" Then
              Call frequency_check _shift 'Each of these is basically the same as (Post #3)
              End If

              If txt_frequency = "Daily" Then
              Call frequency_check _daily
              End If

              If txt_frequency = "Weekly" Then
              Call frequency_check _weekly
              End If

              If txt_frequency = "Monthly" Then
              Call frequency_check _monthly
              End If


              End If

              End Sub
              [/code]

              Comment

              • NeoPa
                Recognized Expert Moderator MVP
                • Oct 2006
                • 32661

                #8
                I'm sorry, but it's still unclear where the code (the stuff with the error in) is being run from.

                This is particularly important as the line where the error occurs is unspecific code. It works on the current object (not on the form that's yet to be opened) so without knowing where we are at the time of execution I can see no way to determine what's going wrong.

                Comment

                • MindBender77
                  New Member
                  • Jul 2007
                  • 233

                  #9
                  I'm sorry for being unclear,Neopa. I do appreciate all your help. I'm going to attempt to find the solution through alittle trial and error since I'm between projects. I don't want to fill this thread with useless code snippits and waste yours and others time when it could be used helping others. I'll post the solution when it is found.

                  Thanks Again,
                  Bender

                  Comment

                  • NeoPa
                    Recognized Expert Moderator MVP
                    • Oct 2006
                    • 32661

                    #10
                    Originally posted by MindBender77 (from post #3)
                    ...
                    [code=vb]DoCmd.GoToRecor d , , acNext 'This Is Where The Error Occurs[/code]
                    ...
                    OK No worries.

                    If I can just share my thoughts so far, they may be of some help.

                    I'm guessing (can't be sure) that this line is intended to operate within a form (possibly the one that has yet to be called) but is actually operating elsewhere. This is a side-effect of the API provided to be very general purpose (DoCmd...). If possible (it isn't in all cases unfortunately) re-code this to refer to an object explicitly. This has a side-effect of being more obvious when read too (so is better coding practice generally).

                    Good luck with your attempts and let us know how you get on :)

                    Comment

                    Working...