Page 3 of 3 FirstFirst 123
Results 31 to 44 of 44
  1. #31
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556

    Quote Originally Posted by GregOwen View Post
    Again, post the Debug.Print output ?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  2. #32
    Blings's Avatar
    Blings is offline Competent Performer
    Windows 10 Office 365
    Join Date
    May 2020
    Location
    London, UK
    Posts
    125
    Debug.Print output to error message on post #27.

    Code:
    INSERT INTO tblProvisionalQuotes ( QuoteNo, Revision, Project, RaisedBYID, QuoteValue, MonthExpected, StatsuID, SourceID, Specifier, Notes, SalesEngineerId, Delivery, ValidTo, OrderedBy, OrderDate, OrderNo, OrderValue, DateCreated, FollowUpDate, AreaID ) SELECT tblProvisionalQuotes.QuoteNo, "1B", tblProvisionalQuotes.Project, tblProvisionalQuotes.RaisedBYID, tblProvisionalQuotes.QuoteValue, tblProvisionalQuotes.MonthExpected, tblProvisionalQuotes.StatsuID, tblProvisionalQuotes.SourceID, tblProvisionalQuotes.Specifier, tblProvisionalQuotes.Notes, tblProvisionalQuotes.SalesEngineerId, tblProvisionalQuotes.Delivery, tblProvisionalQuotes.ValidTo, tblProvisionalQuotes.OrderedBy, tblProvisionalQuotes.OrderDate, tblProvisionalQuotes.OrderNo, tblProvisionalQuotes.OrderValue, tblProvisionalQuotes.DateCreated, tblProvisionalQuotes.FollowUpDate, tblProvisionalQuotes.AreaID 
    FROM tblProvisionalQuotes 
    WHERE (((tblProvisionalQuotes.ProvisionalQuoteId)=1120));
    INSERT INTO tblQuoteDetails ( ProvisionalQuoteID, TypeID, ElementID, CodeID, Code, Description, Qty, DiscountID, Tax, Delivery, SalesPrice, LineTotal, Ref ) 
    SELECT 1154, tblQuoteDetails.TypeID, tblQuoteDetails.ElementID, tblQuoteDetails.CodeID, tblQuoteDetails.Code, tblQuoteDetails.Description, tblQuoteDetails.Qty, tblQuoteDetails.DiscountID, tblQuoteDetails.Tax, tblQuoteDetails.Delivery, tblQuoteDetails.SalesPrice, tblQuoteDetails.LineTotal, tblQuoteDetails.Ref 
    FROM tblQuoteDetails 
    WHERE (((ProvisionalQuoteID)=1120));

  3. #33
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Just run
    Code:
    SELECT 1154, tblQuoteDetails.TypeID, tblQuoteDetails.ElementID, tblQuoteDetails.CodeID, tblQuoteDetails.Code, tblQuoteDetails.Description, tblQuoteDetails.Qty, tblQuoteDetails.DiscountID, tblQuoteDetails.Tax, tblQuoteDetails.Delivery, tblQuoteDetails.SalesPrice, tblQuoteDetails.LineTotal, tblQuoteDetails.Ref 
    FROM tblQuoteDetails 
    WHERE (((ProvisionalQuoteID)=1120));
    and see what that produces. Does it provide a value for each field?

    I cannot see anything wrong at present, but then I am not an expert.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  4. #34
    Blings's Avatar
    Blings is offline Competent Performer
    Windows 10 Office 365
    Join Date
    May 2020
    Location
    London, UK
    Posts
    125
    What should I comment out in order to run just that as above?

  5. #35
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Just copy what I copied and put it into a new query sql window and run it?

    This is part of the benefit of printing the sql. Not only do you get to see if the syntax is correct, you can then run it and see if it produces/updates what you *think* it does?

    Parts of it like now, or the whole lot. Also pasting into the sql window highlights syntax errors.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  6. #36
    Blings's Avatar
    Blings is offline Competent Performer
    Windows 10 Office 365
    Join Date
    May 2020
    Location
    London, UK
    Posts
    125
    Okay, we are nearly there! I created a new sql query and ran that which threw an error on the SalesPrice which should have been named "SalePrice". I've now fixed that, however, I need to now configure the letter incrementing from my original quote as when I duplicate a quote no. for the first time it's putting "!" after the quote no. when it should rather be the letter "a" after the quote no.

    E.g. quote 500 needs to be revised, create revision button is clicked which duplicates quote 500 as quote 500a.

    What can I tell you in order to fix this?

  7. #37
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,165
    Can you show us the code for the IncrementLetter2 function?

  8. #38
    Blings's Avatar
    Blings is offline Competent Performer
    Windows 10 Office 365
    Join Date
    May 2020
    Location
    London, UK
    Posts
    125
    Module: "mdlLetter"
    Code:
    Public Function IncrementLetter2(ByVal Alphanum As Variant) As String    Dim strLetter As String
        Dim strNumericPart As String
        
        If IsNumeric(Alphanum) Then
            strNumericPart = Alphanum
            IncrementLetter2 = Alphanum & "A"
        Else
            strNumericPart = Left$(Alphanum, Len(Alphanum) - 1)
            strLetter = Right$(Alphanum, 1)
            IncrementLetter2 = strNumericPart & Chr(Asc(strLetter) + 1)
        End If
    End Function
    Module: "Module1"
    Code:
    Public Function StrNulls(vntField As Variant) As String 
        If vntField = " " Then
            StrNulls = "1"
        Else
            StrNulls = Trim$(CStr(vntField))
        End If
     
    End Function
    This is the code from my original database which does the duplication excluding the tblQuoteDetails which is what we are trying to do which I think we have achieved but now need to incorporate the letter increment correctly for a quote created for the first time:
    Code:
    Private Sub cmdDup_Click()
    
    Dim strSQL As String
    
    
    Dim strProject As String
    Dim dteFollowUpDate As Date
    Dim lngQuoteNo As Long
    Dim strRevision As String
    Dim lngRaisedByID As Long
    Dim strQuoteValue As String
    Dim dteDateCreated As Date
    Dim dteMonthExpected As Date
    Dim lngStatusID As Long
    Dim lngSourceID As Long
    Dim lngSalesEngineerID As Long
    Dim strDelivery As String
    Dim dteValidTo As String
    
    
    strProject = Me.Project
    dteFollowUpDate = Me.FollowUpDate
    lngQuoteNo = Me.QuoteNo
    strRevision = StrNulls(Me.Revision)
    lngRaisedByID = Me.RaisedBYID
    strQuoteValue = Me.QuoteValue
    dteDateCreated = Date
    dteMonthExpected = Me.MonthExpected
    lngStatusID = Me.StatsuID
    lngSourceID = Me.SourceID
    lngSalesEngineerID = Me.SalesEngineerID
    strDelivery = Me.Delivery
    dteValidTo = Me.ValidTo
    
    
    strSQL = "INSERT INTO tblProvisionalQuotes ( Project, FollowUpDate, QuoteNo, Revision, RaisedbyID, QuoteValue, DateCreated, MonthExpected, StatsuID, SourceID, SalesEngineerID, Delivery, ValidTo) " _
    & "Values ('" & strProject & "', " & Format(dteFollowUpDate, "\#dd\-mmm\-yyyy\#") & ", " & lngQuoteNo & ",'" & IncrementLetter2(strRevision) & "', " & lngRaisedByID & ", '" & strQuoteValue & _
    "', " & Format(dteDateCreated, "\#dd\-mmm\-yyyy\#") & ", " & Format(dteMonthExpected, "\#dd\-mmm\-yyyy\#") & ", " & lngStatusID & ", " & lngSourceID & ", " & lngSalesEngineerID & ", '" & strDelivery & "', " & Format(dteValidTo, "\#dd\-mmm\-yyyy\#") & ");"
        Debug.Print strSQL
        CurrentDb.Execute strSQL, dbFailOnError
    
    
    MsgBox "Quote Duplicated", vbInformation
    
    
    
    
    
    
    End Sub

  9. #39
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,165
    hmm... The easiest way to get it to returning to the way it was working before would be to change the following line in the code that I gave you:
    Code:
    Revision = IncrementLetter2(Nz(Me.Revision, ""))
    To this:
    Code:
    Revision = IncrementLetter2(StrNulls(Me.Revision))
    ... seems like some funny business going on here though that I don't understand

  10. #40
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Walk through the code line by line with F8, or set breakpoints and examine what is passed to that function.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  11. #41
    Blings's Avatar
    Blings is offline Competent Performer
    Windows 10 Office 365
    Join Date
    May 2020
    Location
    London, UK
    Posts
    125
    Quote Originally Posted by kd2017 View Post
    hmm... The easiest way to get it to returning to the way it was working before would be to change the following line in the code that I gave you:
    Code:
    Revision = IncrementLetter2(Nz(Me.Revision, ""))
    To this:
    Code:
    Revision = IncrementLetter2(StrNulls(Me.Revision))
    ... seems like some funny business going on here though that I don't understand
    Yes! It works! You fixed it! Thank you very much!

  12. #42
    Blings's Avatar
    Blings is offline Competent Performer
    Windows 10 Office 365
    Join Date
    May 2020
    Location
    London, UK
    Posts
    125
    One last question on this thread. I would like to exclude the copying of the 'DateCreated' value from the previous version and insert the current date into the new revision instead of carrying over the previous date. Should the select statement "tblProvisionalQuotes.DateCreated" be tweaked to grab todays date?

    Code:
    sql = sql & "INSERT INTO tblProvisionalQuotes ( QuoteNo, Revision, Project, RaisedBYID, QuoteValue, MonthExpected, StatsuID, SourceID, Specifier, Notes, SalesEngineerId, Delivery, ValidTo, OrderedBy, OrderDate, OrderNo, OrderValue, DateCreated, FollowUpDate, AreaID ) " & vbCrLf
    Code:
    sql = sql & "SELECT tblProvisionalQuotes.QuoteNo, """ & Revision & """, tblProvisionalQuotes.Project, tblProvisionalQuotes.RaisedBYID, tblProvisionalQuotes.QuoteValue, tblProvisionalQuotes.MonthExpected, tblProvisionalQuotes.StatsuID, tblProvisionalQuotes.SourceID, tblProvisionalQuotes.Specifier, tblProvisionalQuotes.Notes, tblProvisionalQuotes.SalesEngineerId, tblProvisionalQuotes.Delivery, tblProvisionalQuotes.ValidTo, tblProvisionalQuotes.OrderedBy, tblProvisionalQuotes.OrderDate, tblProvisionalQuotes.OrderNo, tblProvisionalQuotes.OrderValue, tblProvisionalQuotes.DateCreated, tblProvisionalQuotes.FollowUpDate, tblProvisionalQuotes.AreaID " & vbCrLf

  13. #43
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,157
    Simply Replace the tblProvisionalQuotes.DateCreated, with Date(),
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  14. #44
    Blings's Avatar
    Blings is offline Competent Performer
    Windows 10 Office 365
    Join Date
    May 2020
    Location
    London, UK
    Posts
    125
    Quote Originally Posted by Minty View Post
    Simply Replace the tblProvisionalQuotes.DateCreated, with Date(),
    Wonderful, thank you.

    Code:
    sql = sql & "SELECT tblProvisionalQuotes.QuoteNo, """ & Revision & """, tblProvisionalQuotes.Project, tblProvisionalQuotes.RaisedBYID, tblProvisionalQuotes.QuoteValue, tblProvisionalQuotes.MonthExpected, tblProvisionalQuotes.StatsuID, tblProvisionalQuotes.SourceID, tblProvisionalQuotes.Specifier, tblProvisionalQuotes.Notes, tblProvisionalQuotes.SalesEngineerId, tblProvisionalQuotes.Delivery, tblProvisionalQuotes.ValidTo, tblProvisionalQuotes.OrderedBy, tblProvisionalQuotes.OrderDate, tblProvisionalQuotes.OrderNo, tblProvisionalQuotes.OrderValue, Date(), tblProvisionalQuotes.FollowUpDate, tblProvisionalQuotes.AreaID " & vbCrLf

Page 3 of 3 FirstFirst 123
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 7
    Last Post: 02-06-2019, 01:34 PM
  2. Replies: 3
    Last Post: 07-24-2015, 06:39 AM
  3. Replies: 1
    Last Post: 12-18-2012, 02:50 PM
  4. Table design and information duplication
    By pess in forum Database Design
    Replies: 1
    Last Post: 08-11-2011, 10:57 PM
  5. Create a variable from a query created in VBA
    By kaelcarp in forum Programming
    Replies: 4
    Last Post: 06-11-2010, 09:13 PM

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