Results 1 to 9 of 9
  1. #1
    vartaxe is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2015
    Posts
    3

    vba help

    hi,



    can't get this to work properly :/

    Code:
    Private Sub Numéro_du_projet_Click()If Len(Me.Numéro_du_projet & "") < 1 Then
    ElseIf Me.Localité.Column(2) = "" Or Me.Type.Column(2) = "" Then
    MsgBox "Veuillez renseigner la localité et le type de projet."
    Else
    tSeq = Nz(DMax("Séquence", "Projets", "Localité=" & Me.Localité & " and " & "Type=" & Me.Type))
    hiCount = Nz(DLookup("Compteur", "Projets", "Séquence=" & tSeq), 0) + 1
    Me.Numéro_du_projet = Me.Localité.Column(2) & "-" & Me.Type.Column(2) & "-" & Format(Compteur, "000")
    End If
    End Sub
    
    Projets.zip

  2. #2
    vartaxe is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2015
    Posts
    3
    i need to generate project numbers concatenating two fields and increasing count by 1 (every project number has to be unique) so for instance first project in SPAIN for CABLE should be named ES-CA-1 second one ES-CA-2 but if the third one is for instance in another location or type then counter should check for number to use

    location=SPAIN=ES
    type=CABLE=CA

    Len function was just to see if project already had a project number then it should skip it otherwise it could modify the number which isn't good

  3. #3
    CJ_London is online now VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,933
    1. type is a reserved word so may be causing the problem. Try putting it in square brackets but better to change the name
    2.if Localité and type are text then your criteria needs to be

    "Localité='" & Me.Localité & "' and " & "[Type]='" & Me.[Type] & "'"

  4. #4
    vartaxe is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2015
    Posts
    3
    hi,

    still no luck on this

    Code:
    Private Sub Numéro_du_projet_Click()If Len(Me.Numéro_du_projet & "") < 1 Then
         If Me.Localité.Column(2) = "" Or Me.Type.Column(2) = "" Then
              MsgBox "Veuillez renseigner la localité et le type de projet."
              Exit Sub
         End If
         tSeq = Nz(DMax("Séquence", "Projets", "Localité='" & Me.Localité.Column(2) & "' and " & "[Type]='" & Me.Type.Column(2) & "'"), 0)
         hiCount = Nz(DLookup("Compteur", "Projets", "Compteur=" & tSeq & ""), 0) + 1
         Me.Numéro_du_projet = Me.Localité.Column(2) & "-" & Me.Type.Column(2) & "-" & Format(hiCount, "000")
    End If
    End Sub
    thanks for helping

  5. #5
    CJ_London is online now VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,933
    how does 'no luck' translate? you get an error (in which case what is the error number and description?) It doesn't compile? - what error message do you get and what line? you get the wrong result? - in which case provide some sample data and explain what result you want and what you get

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870

  7. #7
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,441
    Combo boxes and list boxes are 0 indexed, so when you use .column(2) you are actually referencing the third column of your combo box or list box, is this what you intend?

    Can you show an example of the data in your PROJETS table? (garbage data will work fine, it just needs to accurately reflect how your data is set up). It would also help to see the SQL behind localite and [type] combo boxes/list boxes

  8. #8
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,441
    Your database modified:

    Projets.zip

  9. #9
    CJ_London is online now VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,933
    I'm dropping out, OP is getting plenty of help from the other forums

Please reply to this thread with any new information or opinions.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums