Results 1 to 6 of 6
  1. #1
    Steven19 is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Jun 2020
    Location
    London
    Posts
    110

    Adapting VBA to merge two UI fields into one

    Hi All

    I have the following code, which is designed to allow me to enter boldt suppliers and a box, each bolt has a sequential number on it with a prefix. Now the table I have has a field for the prefix and the bolt number, but is there a way I can adapt this code so that BoltNum = x Cane become BoltNum = Prefix and X (No spaces)

    Private Sub Command30_Click()
    Dim rs As Recordset, x As Integer
    Set rs = CurrentDb.OpenRecordset("SELECT * FROM Seals WHERE 1=0")
    For x = Me.StartRange To Me.EndRange
    rs.AddNew
    rs!BoltNum = x
    rs!BoxID = Me.Box_ID
    rs!SealTypes = Me.Seal_Types
    rs!SupplierLookup = Me.Supplier
    rs!Prefix = Me.Prefix
    rs!DateAdded = Me.Date_Added
    rs.Update
    Next
    End Sub



    The result in the field now is
    010
    011
    012 etc
    What I want is
    WW010
    WW011
    WW012

    Any help greatly appreciated.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I'd probably leave them separate, but:

    rs!BoltNum = Me.Prefix & x
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Steven19 is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Jun 2020
    Location
    London
    Posts
    110
    I get an debug error when doing that.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    What's the error message? If that field is numeric, you certainly can't put the alpha characters in it.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    Steven19 is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Jun 2020
    Location
    London
    Posts
    110
    sorry no I was half aasleep I forgot one was a text field and the other was a number field. all fine now. thanks,

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    No problem. Like I said, I'd probably keep them separate anyway. Generally it's easier to put things together than split them apart. You can put them together when presenting to users.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. merge two fields at one in report
    By msasan1367 in forum Access
    Replies: 4
    Last Post: 03-30-2013, 02:00 AM
  2. Merge fields (not concatenate)
    By sberti in forum Access
    Replies: 2
    Last Post: 11-30-2012, 12:53 AM
  3. Adapting Excel File to Access Table
    By mbake085 in forum Access
    Replies: 2
    Last Post: 05-18-2011, 10:41 AM
  4. Adapting a fragment code
    By accesscurrymoodle in forum Programming
    Replies: 1
    Last Post: 08-23-2010, 08:28 AM
  5. Merge two fields
    By daviddoria in forum Access
    Replies: 0
    Last Post: 01-31-2009, 09:12 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