Module problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tony Williams

    Module problem

    I have a module called GetDocIndex which calculates a sequential number in a
    control called CommDocNbrtxt. On the BeforeUpdate property of the form I
    have the following code
    Private Sub Form_BeforeUpda te(Cancel As Integer)[color=blue]
    >
    > If Len(Nz(Me.CommD ocNbrtxt, "")) = 0 Then
    > Me.CommDocNbrtx t.Value = GetDocIndex
    > End If[/color]
    The control isn't updated when I open the form and when I save the form I
    get a message that points to this code that says Compile error Expected
    variable or function not module. If I put the module code in the form module
    it doesn't work either.
    Can anyone help here?
    TIA


  • Wayne Morgan

    #2
    Re: Module problem

    You can't call a "module", you have to call procedures in the module. Make sure that none
    of the procedures have the same name as any module or any built in procedure.

    --
    Wayne Morgan


    "Tony Williams" <tw@tcp.com> wrote in message news:blgvf8$7k$ 1@titan.btinter net.com...[color=blue]
    > I have a module called GetDocIndex which calculates a sequential number in a
    > control called CommDocNbrtxt. On the BeforeUpdate property of the form I
    > have the following code
    > Private Sub Form_BeforeUpda te(Cancel As Integer)[color=green]
    > >
    > > If Len(Nz(Me.CommD ocNbrtxt, "")) = 0 Then
    > > Me.CommDocNbrtx t.Value = GetDocIndex
    > > End If[/color]
    > The control isn't updated when I open the form and when I save the form I
    > get a message that points to this code that says Compile error Expected
    > variable or function not module. If I put the module code in the form module
    > it doesn't work either.
    > Can anyone help here?
    > TIA
    >
    >[/color]


    Comment

    • Tony Williams

      #3
      Re: Module problem

      Thanks Wayne but being a newbie I'm a little confused. Here is the code for
      my "function"
      Function GetDocIndex() As String

      Dim rsDocs As DAO.Recordset
      Dim intDocIdx As Integer
      Dim strLastIdx As String, strNewIdx As String, strSQL As String

      ' Get the last index for this year
      strSQL = "SELECT Max([CommDocNbrtxt]) As [LastDocIdx] " & _
      "FROM [tblDocuments] " & _
      "WHERE (Right([CommDocNbrtxt], 2) = '" & _
      Right(CStr(Year (Date)), 2) & "');"
      Set rsDocs = CurrentDb.OpenR ecordset(strSQL )
      With rsDocs
      If Not .RecordCount = 0 Then strLastIdx =
      ..Fields("LastD ocIdx").Value
      .Close
      End With
      Set rsDocs = Nothing

      ' Convert last index to integer or leave as zero
      If Not strLastIdx = "" Then intDocIdx = CInt(strLastIdx )

      ' Increment the index
      intDocIdx = intDocIdx + 1

      ' Append the 2 digit year as decimal value
      strNewIdx = intDocIdx & "." & Right(CStr(Year (Date)), 2)

      ' Return the new index
      GetDocIndex = strNewIdx

      End Function

      As I said earlier if I put this code as a function in the form I still don't
      get my control to update with the right numbers numbers. What am I doing
      wrong here?
      Thanks
      Tony
      "Wayne Morgan" <comprev_gothro ughthenewsgroup @hotmail.com> wrote in message
      news:IyTeb.8099 $bx7.1755@newss vr33.news.prodi gy.com...[color=blue]
      > You can't call a "module", you have to call procedures in the module. Make[/color]
      sure that none[color=blue]
      > of the procedures have the same name as any module or any built in[/color]
      procedure.[color=blue]
      >
      > --
      > Wayne Morgan
      >
      >
      > "Tony Williams" <tw@tcp.com> wrote in message[/color]
      news:blgvf8$7k$ 1@titan.btinter net.com...[color=blue][color=green]
      > > I have a module called GetDocIndex which calculates a sequential number[/color][/color]
      in a[color=blue][color=green]
      > > control called CommDocNbrtxt. On the BeforeUpdate property of the form I
      > > have the following code
      > > Private Sub Form_BeforeUpda te(Cancel As Integer)[color=darkred]
      > > >
      > > > If Len(Nz(Me.CommD ocNbrtxt, "")) = 0 Then
      > > > Me.CommDocNbrtx t.Value = GetDocIndex
      > > > End If[/color]
      > > The control isn't updated when I open the form and when I save the form[/color][/color]
      I[color=blue][color=green]
      > > get a message that points to this code that says Compile error Expected
      > > variable or function not module. If I put the module code in the form[/color][/color]
      module[color=blue][color=green]
      > > it doesn't work either.
      > > Can anyone help here?
      > > TIA
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • Wayne Morgan

        #4
        Re: Module problem

        Where are you putting this code in the form? If you are just adding the function, you need
        something to tell Access to run the function. Under what circumstances do you want this
        function to run? That will determine where you place the call to this function. For
        example, if you want the function to run each time you move to another record, you would
        place a call to it in the Form's OnCurrent event. You could also use it as the Control
        Source for an unbound text box. To do that, set the Control Source of the text box to

        =GetDocIndex

        --
        Wayne Morgan


        "Tony Williams" <tw@tcp.com> wrote in message news:blh1n4$4pg $1@titan.btinte rnet.com...[color=blue]
        > Thanks Wayne but being a newbie I'm a little confused. Here is the code for
        > my "function"
        > Function GetDocIndex() As String
        >
        > Dim rsDocs As DAO.Recordset
        > Dim intDocIdx As Integer
        > Dim strLastIdx As String, strNewIdx As String, strSQL As String
        >
        > ' Get the last index for this year
        > strSQL = "SELECT Max([CommDocNbrtxt]) As [LastDocIdx] " & _
        > "FROM [tblDocuments] " & _
        > "WHERE (Right([CommDocNbrtxt], 2) = '" & _
        > Right(CStr(Year (Date)), 2) & "');"
        > Set rsDocs = CurrentDb.OpenR ecordset(strSQL )
        > With rsDocs
        > If Not .RecordCount = 0 Then strLastIdx =
        > .Fields("LastDo cIdx").Value
        > .Close
        > End With
        > Set rsDocs = Nothing
        >
        > ' Convert last index to integer or leave as zero
        > If Not strLastIdx = "" Then intDocIdx = CInt(strLastIdx )
        >
        > ' Increment the index
        > intDocIdx = intDocIdx + 1
        >
        > ' Append the 2 digit year as decimal value
        > strNewIdx = intDocIdx & "." & Right(CStr(Year (Date)), 2)
        >
        > ' Return the new index
        > GetDocIndex = strNewIdx
        >
        > End Function
        >
        > As I said earlier if I put this code as a function in the form I still don't
        > get my control to update with the right numbers numbers. What am I doing
        > wrong here?
        > Thanks
        > Tony[/color]


        Comment

        • Tony Williams

          #5
          Re: Module problem

          Wayne, I have added the function and am using this code in the forms Before
          Update property
          Private Sub Form_BeforeUpda te(Cancel As Integer)

          If Len(Nz(Me.CommD ocNbrtxt, "")) = 0 Then
          Me.CommDocNbrtx t.Value = GetDocIndex
          End If

          End Sub
          The control I want the number to appear in is CommDocIndextxt
          I am not correct here? It doesn't work
          Thanks
          Tony
          "Wayne Morgan" <comprev_gothro ughthenewsgroup @hotmail.com> wrote in message
          news:hmUeb.8101 $BB7.481@newssv r33.news.prodig y.com...[color=blue]
          > Where are you putting this code in the form? If you are just adding the[/color]
          function, you need[color=blue]
          > something to tell Access to run the function. Under what circumstances do[/color]
          you want this[color=blue]
          > function to run? That will determine where you place the call to this[/color]
          function. For[color=blue]
          > example, if you want the function to run each time you move to another[/color]
          record, you would[color=blue]
          > place a call to it in the Form's OnCurrent event. You could also use it as[/color]
          the Control[color=blue]
          > Source for an unbound text box. To do that, set the Control Source of the[/color]
          text box to[color=blue]
          >
          > =GetDocIndex
          >
          > --
          > Wayne Morgan
          >
          >
          > "Tony Williams" <tw@tcp.com> wrote in message[/color]
          news:blh1n4$4pg $1@titan.btinte rnet.com...[color=blue][color=green]
          > > Thanks Wayne but being a newbie I'm a little confused. Here is the code[/color][/color]
          for[color=blue][color=green]
          > > my "function"
          > > Function GetDocIndex() As String
          > >
          > > Dim rsDocs As DAO.Recordset
          > > Dim intDocIdx As Integer
          > > Dim strLastIdx As String, strNewIdx As String, strSQL As String
          > >
          > > ' Get the last index for this year
          > > strSQL = "SELECT Max([CommDocNbrtxt]) As [LastDocIdx] " & _
          > > "FROM [tblDocuments] " & _
          > > "WHERE (Right([CommDocNbrtxt], 2) = '" & _
          > > Right(CStr(Year (Date)), 2) & "');"
          > > Set rsDocs = CurrentDb.OpenR ecordset(strSQL )
          > > With rsDocs
          > > If Not .RecordCount = 0 Then strLastIdx =
          > > .Fields("LastDo cIdx").Value
          > > .Close
          > > End With
          > > Set rsDocs = Nothing
          > >
          > > ' Convert last index to integer or leave as zero
          > > If Not strLastIdx = "" Then intDocIdx = CInt(strLastIdx )
          > >
          > > ' Increment the index
          > > intDocIdx = intDocIdx + 1
          > >
          > > ' Append the 2 digit year as decimal value
          > > strNewIdx = intDocIdx & "." & Right(CStr(Year (Date)), 2)
          > >
          > > ' Return the new index
          > > GetDocIndex = strNewIdx
          > >
          > > End Function
          > >
          > > As I said earlier if I put this code as a function in the form I still[/color][/color]
          don't[color=blue][color=green]
          > > get my control to update with the right numbers numbers. What am I doing
          > > wrong here?
          > > Thanks
          > > Tony[/color]
          >
          >[/color]


          Comment

          • Tony Williams

            #6
            Re: Module problem

            Sorry forgot I want the control to be populated with a new number each time
            a new record is created
            Tony
            "Wayne Morgan" <comprev_gothro ughthenewsgroup @hotmail.com> wrote in message
            news:hmUeb.8101 $BB7.481@newssv r33.news.prodig y.com...[color=blue]
            > Where are you putting this code in the form? If you are just adding the[/color]
            function, you need[color=blue]
            > something to tell Access to run the function. Under what circumstances do[/color]
            you want this[color=blue]
            > function to run? That will determine where you place the call to this[/color]
            function. For[color=blue]
            > example, if you want the function to run each time you move to another[/color]
            record, you would[color=blue]
            > place a call to it in the Form's OnCurrent event. You could also use it as[/color]
            the Control[color=blue]
            > Source for an unbound text box. To do that, set the Control Source of the[/color]
            text box to[color=blue]
            >
            > =GetDocIndex
            >
            > --
            > Wayne Morgan
            >
            >
            > "Tony Williams" <tw@tcp.com> wrote in message[/color]
            news:blh1n4$4pg $1@titan.btinte rnet.com...[color=blue][color=green]
            > > Thanks Wayne but being a newbie I'm a little confused. Here is the code[/color][/color]
            for[color=blue][color=green]
            > > my "function"
            > > Function GetDocIndex() As String
            > >
            > > Dim rsDocs As DAO.Recordset
            > > Dim intDocIdx As Integer
            > > Dim strLastIdx As String, strNewIdx As String, strSQL As String
            > >
            > > ' Get the last index for this year
            > > strSQL = "SELECT Max([CommDocNbrtxt]) As [LastDocIdx] " & _
            > > "FROM [tblDocuments] " & _
            > > "WHERE (Right([CommDocNbrtxt], 2) = '" & _
            > > Right(CStr(Year (Date)), 2) & "');"
            > > Set rsDocs = CurrentDb.OpenR ecordset(strSQL )
            > > With rsDocs
            > > If Not .RecordCount = 0 Then strLastIdx =
            > > .Fields("LastDo cIdx").Value
            > > .Close
            > > End With
            > > Set rsDocs = Nothing
            > >
            > > ' Convert last index to integer or leave as zero
            > > If Not strLastIdx = "" Then intDocIdx = CInt(strLastIdx )
            > >
            > > ' Increment the index
            > > intDocIdx = intDocIdx + 1
            > >
            > > ' Append the 2 digit year as decimal value
            > > strNewIdx = intDocIdx & "." & Right(CStr(Year (Date)), 2)
            > >
            > > ' Return the new index
            > > GetDocIndex = strNewIdx
            > >
            > > End Function
            > >
            > > As I said earlier if I put this code as a function in the form I still[/color][/color]
            don't[color=blue][color=green]
            > > get my control to update with the right numbers numbers. What am I doing
            > > wrong here?
            > > Thanks
            > > Tony[/color]
            >
            >[/color]


            Comment

            • Wayne Morgan

              #7
              Re: Module problem

              You say you want the result of GetDocIndex to appear in the ComDocIndextxt control, yet
              you are assigning the result to the ComDocNbrtxt control.

              Just to play it safe, do your controls have a different name than the fields they are
              bound to? If the control's Control Source and the control's name are the same, you can run
              into problems. This is usually handled by placing a prefix on the name of the control.
              (i.e. Field Name = MyField, Control Name = txtMyField). I see you've appended txt to the
              end of the names you are using, have you done that to accomplish this?

              Also, you are doing this in the BeforeUpdate event. If it does place the value, it may do
              so quickly, save the record, and move to the next record. You may not see it unless you go
              back to that record and look for it.

              You mentioned that you want to do this for a new record, what about an old record that the
              field was left blank on? The way you currently have it, if you make a change to that old
              record it would also run the function to update the old record with a number. If you want
              to limit it to only new records, you could add an additional If statement.

              If Me.NewRecord Then.....

              --
              Wayne Morgan


              "Tony Williams" <tw@tcp.com> wrote in message news:blh470$2ij $1@sparta.btint ernet.com...[color=blue]
              > Wayne, I have added the function and am using this code in the forms Before
              > Update property
              > Private Sub Form_BeforeUpda te(Cancel As Integer)
              >
              > If Len(Nz(Me.CommD ocNbrtxt, "")) = 0 Then
              > Me.CommDocNbrtx t.Value = GetDocIndex
              > End If
              >
              > End Sub
              > The control I want the number to appear in is CommDocIndextxt
              > I am not correct here? It doesn't work
              > Thanks
              > Tony
              > "Wayne Morgan" <comprev_gothro ughthenewsgroup @hotmail.com> wrote in message
              > news:hmUeb.8101 $BB7.481@newssv r33.news.prodig y.com...[color=green]
              > > Where are you putting this code in the form? If you are just adding the[/color]
              > function, you need[color=green]
              > > something to tell Access to run the function. Under what circumstances do[/color]
              > you want this[color=green]
              > > function to run? That will determine where you place the call to this[/color]
              > function. For[color=green]
              > > example, if you want the function to run each time you move to another[/color]
              > record, you would[color=green]
              > > place a call to it in the Form's OnCurrent event. You could also use it as[/color]
              > the Control[color=green]
              > > Source for an unbound text box. To do that, set the Control Source of the[/color]
              > text box to[color=green]
              > >
              > > =GetDocIndex
              > >
              > > --
              > > Wayne Morgan
              > >
              > >
              > > "Tony Williams" <tw@tcp.com> wrote in message[/color]
              > news:blh1n4$4pg $1@titan.btinte rnet.com...[color=green][color=darkred]
              > > > Thanks Wayne but being a newbie I'm a little confused. Here is the code[/color][/color]
              > for[color=green][color=darkred]
              > > > my "function"
              > > > Function GetDocIndex() As String
              > > >
              > > > Dim rsDocs As DAO.Recordset
              > > > Dim intDocIdx As Integer
              > > > Dim strLastIdx As String, strNewIdx As String, strSQL As String
              > > >
              > > > ' Get the last index for this year
              > > > strSQL = "SELECT Max([CommDocNbrtxt]) As [LastDocIdx] " & _
              > > > "FROM [tblDocuments] " & _
              > > > "WHERE (Right([CommDocNbrtxt], 2) = '" & _
              > > > Right(CStr(Year (Date)), 2) & "');"
              > > > Set rsDocs = CurrentDb.OpenR ecordset(strSQL )
              > > > With rsDocs
              > > > If Not .RecordCount = 0 Then strLastIdx =
              > > > .Fields("LastDo cIdx").Value
              > > > .Close
              > > > End With
              > > > Set rsDocs = Nothing
              > > >
              > > > ' Convert last index to integer or leave as zero
              > > > If Not strLastIdx = "" Then intDocIdx = CInt(strLastIdx )
              > > >
              > > > ' Increment the index
              > > > intDocIdx = intDocIdx + 1
              > > >
              > > > ' Append the 2 digit year as decimal value
              > > > strNewIdx = intDocIdx & "." & Right(CStr(Year (Date)), 2)
              > > >
              > > > ' Return the new index
              > > > GetDocIndex = strNewIdx
              > > >
              > > > End Function
              > > >
              > > > As I said earlier if I put this code as a function in the form I still[/color][/color]
              > don't[color=green][color=darkred]
              > > > get my control to update with the right numbers numbers. What am I doing
              > > > wrong here?
              > > > Thanks
              > > > Tony[/color]
              > >
              > >[/color]
              >
              >[/color]


              Comment

              • Tony Williams

                #8
                Re: Module problem

                Thanks Wayne, I think I get confused with field name and control name I
                assumed they had to be the same. So, do I make the control source = field
                name in the table and the control name whatever I like. In which case when I
                want to refer to the field in code or a report do I use the control source
                name. If that's the case what is the purpose of the control name?

                Sorry about the confusion the control is ComDocNbrtxt, I appended txt to
                names so that I know it's a text field, have I got the convention the wrong
                way round?

                Being a newbie at this at 58 means I have to work harder on the grey cells
                to make them cooperate!!!
                But thanks for your patience and advice, I'll now try and put it into
                practice and let you know how I got on.

                Tony
                "Wayne Morgan" <comprev_gothro ughthenewsgroup @hotmail.com> wrote in message
                news:Dq_eb.1179 0$ns.6801@newss vr31.news.prodi gy.com...[color=blue]
                > You say you want the result of GetDocIndex to appear in the ComDocIndextxt[/color]
                control, yet[color=blue]
                > you are assigning the result to the ComDocNbrtxt control.
                >
                > Just to play it safe, do your controls have a different name than the[/color]
                fields they are[color=blue]
                > bound to? If the control's Control Source and the control's name are the[/color]
                same, you can run[color=blue]
                > into problems. This is usually handled by placing a prefix on the name of[/color]
                the control.[color=blue]
                > (i.e. Field Name = MyField, Control Name = txtMyField). I see you've[/color]
                appended txt to the[color=blue]
                > end of the names you are using, have you done that to accomplish this?
                >
                > Also, you are doing this in the BeforeUpdate event. If it does place the[/color]
                value, it may do[color=blue]
                > so quickly, save the record, and move to the next record. You may not see[/color]
                it unless you go[color=blue]
                > back to that record and look for it.
                >
                > You mentioned that you want to do this for a new record, what about an old[/color]
                record that the[color=blue]
                > field was left blank on? The way you currently have it, if you make a[/color]
                change to that old[color=blue]
                > record it would also run the function to update the old record with a[/color]
                number. If you want[color=blue]
                > to limit it to only new records, you could add an additional If statement.
                >
                > If Me.NewRecord Then.....
                >
                > --
                > Wayne Morgan
                >
                >
                > "Tony Williams" <tw@tcp.com> wrote in message[/color]
                news:blh470$2ij $1@sparta.btint ernet.com...[color=blue][color=green]
                > > Wayne, I have added the function and am using this code in the forms[/color][/color]
                Before[color=blue][color=green]
                > > Update property
                > > Private Sub Form_BeforeUpda te(Cancel As Integer)
                > >
                > > If Len(Nz(Me.CommD ocNbrtxt, "")) = 0 Then
                > > Me.CommDocNbrtx t.Value = GetDocIndex
                > > End If
                > >
                > > End Sub
                > > The control I want the number to appear in is CommDocIndextxt
                > > I am not correct here? It doesn't work
                > > Thanks
                > > Tony
                > > "Wayne Morgan" <comprev_gothro ughthenewsgroup @hotmail.com> wrote in[/color][/color]
                message[color=blue][color=green]
                > > news:hmUeb.8101 $BB7.481@newssv r33.news.prodig y.com...[color=darkred]
                > > > Where are you putting this code in the form? If you are just adding[/color][/color][/color]
                the[color=blue][color=green]
                > > function, you need[color=darkred]
                > > > something to tell Access to run the function. Under what circumstances[/color][/color][/color]
                do[color=blue][color=green]
                > > you want this[color=darkred]
                > > > function to run? That will determine where you place the call to this[/color]
                > > function. For[color=darkred]
                > > > example, if you want the function to run each time you move to another[/color]
                > > record, you would[color=darkred]
                > > > place a call to it in the Form's OnCurrent event. You could also use[/color][/color][/color]
                it as[color=blue][color=green]
                > > the Control[color=darkred]
                > > > Source for an unbound text box. To do that, set the Control Source of[/color][/color][/color]
                the[color=blue][color=green]
                > > text box to[color=darkred]
                > > >
                > > > =GetDocIndex
                > > >
                > > > --
                > > > Wayne Morgan
                > > >
                > > >
                > > > "Tony Williams" <tw@tcp.com> wrote in message[/color]
                > > news:blh1n4$4pg $1@titan.btinte rnet.com...[color=darkred]
                > > > > Thanks Wayne but being a newbie I'm a little confused. Here is the[/color][/color][/color]
                code[color=blue][color=green]
                > > for[color=darkred]
                > > > > my "function"
                > > > > Function GetDocIndex() As String
                > > > >
                > > > > Dim rsDocs As DAO.Recordset
                > > > > Dim intDocIdx As Integer
                > > > > Dim strLastIdx As String, strNewIdx As String, strSQL As String
                > > > >
                > > > > ' Get the last index for this year
                > > > > strSQL = "SELECT Max([CommDocNbrtxt]) As [LastDocIdx] " & _
                > > > > "FROM [tblDocuments] " & _
                > > > > "WHERE (Right([CommDocNbrtxt], 2) = '" & _
                > > > > Right(CStr(Year (Date)), 2) & "');"
                > > > > Set rsDocs = CurrentDb.OpenR ecordset(strSQL )
                > > > > With rsDocs
                > > > > If Not .RecordCount = 0 Then strLastIdx =
                > > > > .Fields("LastDo cIdx").Value
                > > > > .Close
                > > > > End With
                > > > > Set rsDocs = Nothing
                > > > >
                > > > > ' Convert last index to integer or leave as zero
                > > > > If Not strLastIdx = "" Then intDocIdx = CInt(strLastIdx )
                > > > >
                > > > > ' Increment the index
                > > > > intDocIdx = intDocIdx + 1
                > > > >
                > > > > ' Append the 2 digit year as decimal value
                > > > > strNewIdx = intDocIdx & "." & Right(CStr(Year (Date)), 2)
                > > > >
                > > > > ' Return the new index
                > > > > GetDocIndex = strNewIdx
                > > > >
                > > > > End Function
                > > > >
                > > > > As I said earlier if I put this code as a function in the form I[/color][/color][/color]
                still[color=blue][color=green]
                > > don't[color=darkred]
                > > > > get my control to update with the right numbers numbers. What am I[/color][/color][/color]
                doing[color=blue][color=green][color=darkred]
                > > > > wrong here?
                > > > > Thanks
                > > > > Tony
                > > >
                > > >[/color]
                > >
                > >[/color]
                >
                >[/color]


                Comment

                • Wayne Morgan

                  #9
                  Re: Module problem

                  Yes, you can make the control name whatever you want, but I would recommend keeping it
                  similar to the field name so that you don't have a lot to remember. Sometimes with both
                  names the same, Access doesn't know which of the two items you are referring to and it
                  will cause a problem.

                  A good example of naming conventions can be found at


                  Does the function return the correct value, just the value doesn't go into the control?

                  --
                  Wayne Morgan


                  "Tony Williams" <tw@tcp.com> wrote in message news:bljlvv$4h6 $1@sparta.btint ernet.com...[color=blue]
                  > Thanks Wayne, I think I get confused with field name and control name I
                  > assumed they had to be the same. So, do I make the control source = field
                  > name in the table and the control name whatever I like. In which case when I
                  > want to refer to the field in code or a report do I use the control source
                  > name. If that's the case what is the purpose of the control name?
                  >
                  > Sorry about the confusion the control is ComDocNbrtxt, I appended txt to
                  > names so that I know it's a text field, have I got the convention the wrong
                  > way round?
                  >
                  > Being a newbie at this at 58 means I have to work harder on the grey cells
                  > to make them cooperate!!!
                  > But thanks for your patience and advice, I'll now try and put it into
                  > practice and let you know how I got on.[/color]


                  Comment

                  • Tony Williams

                    #10
                    Re: Module problem

                    I have the control CommDocNbrtxt on my form as a General Number and all that
                    appears in the control on a new record is a "0", on current records the
                    control is blank.
                    The latest state is this:
                    I have the code as a function in my form module, with the function called
                    GetDocIndex, the first line being
                    Function getDocIndex() As String
                    In the OnCurrent property of the form I have the following code
                    Private Sub Form_Current()
                    If Me.CommDocNbrtx t = "" Then
                    Me.CommDocNbrtx t.Value = getDocIndex
                    End If
                    End Sub

                    At the moment the control name and control source are both CommDocNbrtxt .
                    If I change the control name to say Docnbr which name do I use in the
                    Function and On Current property, the control name or the control source?

                    Thanks for the link for conventions I'll change all my names when I've got
                    this to work!!

                    I am wondering whether I could get some simpler code which just gives me
                    sequential numbers and concatenate the year from another field but that's
                    not what my friend wants and that would be like giving in!!
                    Thanks again for your help.
                    Tony

                    "Wayne Morgan" <comprev_gothro ughthenewsgroup @hotmail.com> wrote in message
                    news:%Refb.2262 $q34.236@newssv r24.news.prodig y.com...[color=blue]
                    > Yes, you can make the control name whatever you want, but I would[/color]
                    recommend keeping it[color=blue]
                    > similar to the field name so that you don't have a lot to remember.[/color]
                    Sometimes with both[color=blue]
                    > names the same, Access doesn't know which of the two items you are[/color]
                    referring to and it[color=blue]
                    > will cause a problem.
                    >
                    > A good example of naming conventions can be found at
                    > http://www.mvps.org/access/general/gen0012.htm
                    >
                    > Does the function return the correct value, just the value doesn't go into[/color]
                    the control?[color=blue]
                    >
                    > --
                    > Wayne Morgan
                    >
                    >
                    > "Tony Williams" <tw@tcp.com> wrote in message[/color]
                    news:bljlvv$4h6 $1@sparta.btint ernet.com...[color=blue][color=green]
                    > > Thanks Wayne, I think I get confused with field name and control name I
                    > > assumed they had to be the same. So, do I make the control source =[/color][/color]
                    field[color=blue][color=green]
                    > > name in the table and the control name whatever I like. In which case[/color][/color]
                    when I[color=blue][color=green]
                    > > want to refer to the field in code or a report do I use the control[/color][/color]
                    source[color=blue][color=green]
                    > > name. If that's the case what is the purpose of the control name?
                    > >
                    > > Sorry about the confusion the control is ComDocNbrtxt, I appended txt to
                    > > names so that I know it's a text field, have I got the convention the[/color][/color]
                    wrong[color=blue][color=green]
                    > > way round?
                    > >
                    > > Being a newbie at this at 58 means I have to work harder on the grey[/color][/color]
                    cells[color=blue][color=green]
                    > > to make them cooperate!!!
                    > > But thanks for your patience and advice, I'll now try and put it into
                    > > practice and let you know how I got on.[/color]
                    >
                    >[/color]


                    Comment

                    • Wayne Morgan

                      #11
                      Re: Module problem

                      I would use the control's name. There are several reasons for this, but the main one is
                      laziness. If you use the control name, when you type "Me." as soon as you hit the period
                      you will get a list of controls on the form along with other acceptable items for Me. This
                      will limit your typing and help prevent typos.

                      --
                      Wayne Morgan


                      "Tony Williams" <tw@tcp.com> wrote in message news:blk2mb$13h $1@sparta.btint ernet.com...[color=blue]
                      > I have the control CommDocNbrtxt on my form as a General Number and all that
                      > appears in the control on a new record is a "0", on current records the
                      > control is blank.
                      > The latest state is this:
                      > I have the code as a function in my form module, with the function called
                      > GetDocIndex, the first line being
                      > Function getDocIndex() As String
                      > In the OnCurrent property of the form I have the following code
                      > Private Sub Form_Current()
                      > If Me.CommDocNbrtx t = "" Then
                      > Me.CommDocNbrtx t.Value = getDocIndex
                      > End If
                      > End Sub
                      >
                      > At the moment the control name and control source are both CommDocNbrtxt .
                      > If I change the control name to say Docnbr which name do I use in the
                      > Function and On Current property, the control name or the control source?
                      >
                      > Thanks for the link for conventions I'll change all my names when I've got
                      > this to work!!
                      >
                      > I am wondering whether I could get some simpler code which just gives me
                      > sequential numbers and concatenate the year from another field but that's
                      > not what my friend wants and that would be like giving in!!
                      > Thanks again for your help.
                      > Tony
                      >
                      > "Wayne Morgan" <comprev_gothro ughthenewsgroup @hotmail.com> wrote in message
                      > news:%Refb.2262 $q34.236@newssv r24.news.prodig y.com...[color=green]
                      > > Yes, you can make the control name whatever you want, but I would[/color]
                      > recommend keeping it[color=green]
                      > > similar to the field name so that you don't have a lot to remember.[/color]
                      > Sometimes with both[color=green]
                      > > names the same, Access doesn't know which of the two items you are[/color]
                      > referring to and it[color=green]
                      > > will cause a problem.
                      > >
                      > > A good example of naming conventions can be found at
                      > > http://www.mvps.org/access/general/gen0012.htm
                      > >
                      > > Does the function return the correct value, just the value doesn't go into[/color]
                      > the control?[color=green]
                      > >
                      > > --
                      > > Wayne Morgan
                      > >
                      > >
                      > > "Tony Williams" <tw@tcp.com> wrote in message[/color]
                      > news:bljlvv$4h6 $1@sparta.btint ernet.com...[color=green][color=darkred]
                      > > > Thanks Wayne, I think I get confused with field name and control name I
                      > > > assumed they had to be the same. So, do I make the control source =[/color][/color]
                      > field[color=green][color=darkred]
                      > > > name in the table and the control name whatever I like. In which case[/color][/color]
                      > when I[color=green][color=darkred]
                      > > > want to refer to the field in code or a report do I use the control[/color][/color]
                      > source[color=green][color=darkred]
                      > > > name. If that's the case what is the purpose of the control name?
                      > > >
                      > > > Sorry about the confusion the control is ComDocNbrtxt, I appended txt to
                      > > > names so that I know it's a text field, have I got the convention the[/color][/color]
                      > wrong[color=green][color=darkred]
                      > > > way round?
                      > > >
                      > > > Being a newbie at this at 58 means I have to work harder on the grey[/color][/color]
                      > cells[color=green][color=darkred]
                      > > > to make them cooperate!!!
                      > > > But thanks for your patience and advice, I'll now try and put it into
                      > > > practice and let you know how I got on.[/color]
                      > >
                      > >[/color]
                      >
                      >[/color]


                      Comment

                      • rkc

                        #12
                        Re: Module problem


                        "Wayne Morgan" <comprev_gothro ughthenewsgroup @hotmail.com> wrote in message
                        news:xpjfb.1636 $xJ4.710@newssv r22.news.prodig y.com...[color=blue]
                        > I would use the control's name. There are several reasons for this, but[/color]
                        the main one is[color=blue]
                        > laziness. If you use the control name, when you type "Me." as soon as you[/color]
                        hit the period[color=blue]
                        > you will get a list of controls on the form along with other acceptable[/color]
                        items for Me. This[color=blue]
                        > will limit your typing and help prevent typos.[/color]

                        I can't tell from the way this thread is going whether Tony is still
                        experiencing
                        his original problem. If he is, you answered his question in your first
                        reply.

                        He has a module named GetDocIndex that contains a function also named
                        GetDocIndex.



                        Comment

                        Working...