Problem with creating new record

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • matt753
    New Member
    • May 2010
    • 91

    Problem with creating new record

    I have three forms: Quotations, Custom Quotations, and Custom QuotationsDetai ls. If I have a basic quote for a customer I need to make I just use Quotations, but if it requires more in-depth details such as extra parts or labor I need to use Custom Quotations to add these. I fill out the CustomQuotation s form that pops up and when I close it it fills in the information in the main Quotations page. Custom Quoatation Details is a subform inside CustomQuotation s that holds each line for a part.

    Right now I can only have one Custom Quote per "Quotations " page. I want to be able to have more than one custom item per quote, but when I click the next record or new record button at the bottom of the Custom Quotations, I get an error in line 3 of the below code: "Syntax error (missing operator) in query expression 'QuoatationID=' " If I comment those lines out (do I really need to check that?) I get an error "Syntax error in INSERT INTO statement" (line 4 of below code) I think the problem for that one is when I debug and mouse-over the "[QuotationID]" text in line 4 of below code, QuotationID is Null.

    Code:
    Private Sub Form_Current()
     
        If DCount("QuotationID", "Quotation_Custom", "QuotationID=" & [QuotationID]) = 0 Then
            CurrentDb.Execute ("INSERT INTO Quotation_Custom (QuotationID, Shipping, Markup, Commission, Exchange) VALUES (" & [QuotationID] & ", .1, .85, 0, .81);")
            Me.Refresh
        End If
        
    
    End Sub
    I also think maybe I need to change how the relationships are set up. What types should I have between the tables?
  • TheSmileyCoder
    Recognized Expert Moderator Top Contributor
    • Dec 2009
    • 2322

    #2
    Thats because you have moved to a new record, and as a new record it does not yet have an ID.

    In 99.9% of cases I will use a Autonumber field as primary table key. The Foreign key of the other tables then has to be Number, Long.

    I dont really see why you would need to run an insert query, why is that?

    Comment

    Working...