Results 1 to 6 of 6
  1. #1
    jfuller is offline Novice
    Windows XP Access 2003
    Join Date
    Apr 2011
    Posts
    5

    Help with code

    Hi All,
    So i managed to get this code to work with my limited VBA knowlege.
    Private Sub RecordNumber_AfterUpdate()
    Me.RecordID = "DQC-R-" & Format(Forms![Record Inventory]![CreatedDate], "mmddyyyy") & Me.Technician & "-" & Me.RecordNumber
    End Sub

    However, there is one little thing that is keeping it from being what i need. the Me.Technician part of the code is reporting the primary key of the data instead of the actual data, which i want. I have a field on a form named TechInitals, which is a list box created from a table containing information for all the technicians in my dept. I need vba to display their initials, instead of the primary key field.
    Any help with this?

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Hi jfuller

    You could try this:
    Code:
     
    Me.RecordID = "DQC-R-" & Format(Forms![Record Inventory]![CreatedDate], "mmddyyyy") & Me.TechInitals.Column(1) & "-" & Me.RecordNumber
    I have assumed that the listbox "TechInitals" has 2 columns, the first one being hidden but holding the numeric "ID" of the Technician.
    The columns of listboxes and comboboxes are indexed (numbered) starting with 0. So the 2nd column would be "Column(1)".
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    jfuller is offline Novice
    Windows XP Access 2003
    Join Date
    Apr 2011
    Posts
    5
    Thanks Bob, i see where you are going, but the field TechInitials is actually from another table. I used a query to populate the listbox for that object. So i think in someway, i have to refer to that table, or the query to get the format that i want?

  4. #4
    jfuller is offline Novice
    Windows XP Access 2003
    Join Date
    Apr 2011
    Posts
    5
    You were right, all i had to do was add column(1). Thanks!!!

  5. #5
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Hi

    You keep calling "TechInitials" a field but it is not because forms do not have Fields. They do have controls. If "TechInitials" is a listbox or a combobox then I think the code I posted should work but it's up to you to whether you even try it.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  6. #6
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Hi

    Glad to know that it is now working as required
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

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

Similar Threads

  1. What does this code mean
    By jo15765 in forum Programming
    Replies: 8
    Last Post: 12-08-2010, 01:05 PM
  2. Word code in Access - How to modify my current code
    By Alexandre Cote in forum Programming
    Replies: 0
    Last Post: 11-15-2010, 08:26 AM
  3. Code in combobox, code in text box
    By float in forum Forms
    Replies: 3
    Last Post: 09-29-2010, 07:12 AM
  4. Access 2003 code vs Access 2007 Code
    By ralphjramirez in forum Access
    Replies: 5
    Last Post: 11-23-2009, 12:33 PM
  5. Help with VBA Code
    By access.newby in forum Forms
    Replies: 1
    Last Post: 11-15-2009, 05:43 AM

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