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
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));
Just run
and see what that produces. Does it provide a value for each field?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));
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
What should I comment out in order to run just that as above?
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
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?
Can you show us the code for the IncrementLetter2 function?
Module: "mdlLetter"
Module: "Module1"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
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:Public Function StrNulls(vntField As Variant) As String If vntField = " " Then StrNulls = "1" Else StrNulls = Trim$(CStr(vntField)) End If End Function
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
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:
To this:Code:Revision = IncrementLetter2(Nz(Me.Revision, ""))
... seems like some funny business going on here though that I don't understandCode:Revision = IncrementLetter2(StrNulls(Me.Revision))
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
Yes! It works! You fixed it! Thank you very much!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:
To this:Code:Revision = IncrementLetter2(Nz(Me.Revision, ""))
... seems like some funny business going on here though that I don't understandCode:Revision = IncrementLetter2(StrNulls(Me.Revision))
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 ) " & vbCrLfCode: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
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 ↓↓
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