pdvsa
asked on
Insert & Syntax Error
Experts,
I have a syntax and I think it is something to do with the underlined part.
do you see it?
thanks.
strSQL = "INSERT INTO Projects ([Status],[Currency],[Crea ted By],[ProjectNo], [Project Name], [Start Date], Notes) " _
& "VALUES ('7'," & DLookup("CurrencyID", "tblCurrencyExchange", "[Currency] = '" & Me.txtCur & "'") & ",'" & [TempVars]![CurrentUserID] & "','?','LC Ref: (but not needed so delete it after appending if want): ' & '" & Me.txtLCRef & "',#" & Format(Date, "m\/d\/yyyy") & "'****APPENDED Dnb*****: " & Format(Date, "m\/d\/yyyy") & "')"
I have a syntax and I think it is something to do with the underlined part.
do you see it?
thanks.
strSQL = "INSERT INTO Projects ([Status],[Currency],[Crea
& "VALUES ('7'," & DLookup("CurrencyID", "tblCurrencyExchange", "[Currency] = '" & Me.txtCur & "'") & ",'" & [TempVars]![CurrentUserID]
try this
strSQL = "INSERT INTO Projects ([Status],[Currency],[Crea ted By],[ProjectNo], [Project Name], [Start Date], Notes) " _
& "VALUES ('7'," & DLookup("CurrencyID", "tblCurrencyExchange", "[Currency] = '" & Me.txtCur & "'") & ",'" & [TempVars]![CurrentUserID] & "','?','LC Ref: (but not needed so delete it after appending if want): ' & '" & Me.txtLCRef & "','" & Format(Date, "m\/d\/yyyy") & "'****APPENDED Dnb*****: " & Format(Date, "m\/d\/yyyy") & "')"
strSQL = "INSERT INTO Projects ([Status],[Currency],[Crea
& "VALUES ('7'," & DLookup("CurrencyID", "tblCurrencyExchange", "[Currency] = '" & Me.txtCur & "'") & ",'" & [TempVars]![CurrentUserID]
ASKER
fyed:
I get a datatype mismatch
here is the debug print sql:
INSERT INTO Projects ([Status],[Currency],[Crea ted By],[ProjectNo], [Project Name], [Start Date], Notes) VALUES ('7',1,'','?','LC Ref: (but not needed so delete it after appending if want): ' & '00440020001844x',#8/26/20 13#,'****A PPENDED Dnb*****: 8/26/2013')
maybe it is clear what is wrong.
thanks
I get a datatype mismatch
here is the debug print sql:
INSERT INTO Projects ([Status],[Currency],[Crea
maybe it is clear what is wrong.
thanks
ASKER
Capricorn: I got the same 3075 syntax error.
ASKER
not sure if it makes a difference but
Projects.[Status] is Number property with row source:
SELECT tblStatus.ID, tblStatus.Status FROM tblStatus ORDER BY tblStatus.Status;
Projects.[Status] is Number property with row source:
SELECT tblStatus.ID, tblStatus.Status FROM tblStatus ORDER BY tblStatus.Status;
ASKER
The Insert did work until I added what was underlined above in original question.
([Status],[Currency] are the 2 additonal fields I added.
Projects.Currency is also number
([Status],[Currency] are the 2 additonal fields I added.
Projects.Currency is also number
i think you are missing a value..
specify which value should go to which field
[Status], --???
[Currency],--???
[Created By], --???
[ProjectNo], --???
[Project Name],--???
[Start Date], --???
[Notes] --???
specify which value should go to which field
[Status], --???
[Currency],--???
[Created By], --???
[ProjectNo], --???
[Project Name],--???
[Start Date], --???
[Notes] --???
If [Status] is number use 7 instead of '7'
Currency is OK with 1
Currency is OK with 1
ASKER
Capricorn:
<specify which value should go to which field
[Currency],--??? answer: the Dlookup
[Created By], --??? answer: TempVars
[ProjectNo], --??? answer: ? (just a question mark)...it is text format
[Project Name],--??? answer: 'LC Ref: (but not needed so delete it after appending if want): ' & '" & Me.txtLCRef & "',
[Start Date], --??? #" & Format(Date, "m\/d\/yyyy") & "#,
[Notes] --??? answer: " & "'****APPENDED Dnb*****: " & Format(Date, "m\/d\/yyyy") & "')"
I know that must be hard to read. I have used fyed's suggestion of closing # just before the APPEND text string.
Actually I said the Insert worked but maybe now it didnt work.
<specify which value should go to which field
1.
[Status], --??? answer: 7[Currency],--??? answer: the Dlookup
[Created By], --??? answer: TempVars
[ProjectNo], --??? answer: ? (just a question mark)...it is text format
[Project Name],--??? answer: 'LC Ref: (but not needed so delete it after appending if want): ' & '" & Me.txtLCRef & "',
[Start Date], --??? #" & Format(Date, "m\/d\/yyyy") & "#,
[Notes] --??? answer: " & "'****APPENDED Dnb*****: " & Format(Date, "m\/d\/yyyy") & "')"
I know that must be hard to read. I have used fyed's suggestion of closing # just before the APPEND text string.
Actually I said the Insert worked but maybe now it didnt work.
ASKER
this is what I have now:
changed '7' to just 7 and used fyed's suggestion of closing # just before the APPEND text string.
strSQL = "INSERT INTO Projects ([Status2],[Currency],[Cre ated By],[ProjectNo], [Project Name], [Start Date], Notes) " _
& "VALUES (7," & DLookup("CurrencyID", "tblCurrencyExchange", "[Currency] = '" & Me.txtCur & "'") & ",'" & [TempVars]![CurrentUserID] & "','?','LC Ref: (but not needed so delete it after appending if want): ' & '" & Me.txtLCRef & "',#" & Format(Date, "m\/d\/yyyy") & "#," & "'****APPENDED Dnb*****: " & Format(Date, "m\/d\/yyyy") & "')"
changed '7' to just 7 and used fyed's suggestion of closing # just before the APPEND text string.
strSQL = "INSERT INTO Projects ([Status2],[Currency],[Cre
& "VALUES (7," & DLookup("CurrencyID", "tblCurrencyExchange", "[Currency] = '" & Me.txtCur & "'") & ",'" & [TempVars]![CurrentUserID]
ASKER
here is the debug print :
INSERT INTO Projects ([Status2],[Currency],[Cre ated By],[ProjectNo], [Project Name], [Start Date], Notes) VALUES (7,1,'','?','LC Ref: (but not needed so delete it after appending if want): ' & '00440020001844x',#8/26/20 13#,'****A PPENDED Dnb*****: 8/26/2013')
INSERT INTO Projects ([Status2],[Currency],[Cre
ASKER
I do get datatype mismatch still
ASKER
properties
Projects.[Status2] = Number
Projects.[Currency] = Number
Projects.[Created By] = Number
Projects.[ProjectNo] = Text
Projects.[Project Name] = Text
Projects.[Start Date] = Date / Time
Projects.[Notes] = Memo
Projects.[Status2] = Number
Projects.[Currency] = Number
Projects.[Created By] = Number
Projects.[ProjectNo] = Text
Projects.[Project Name] = Text
Projects.[Start Date] = Date / Time
Projects.[Notes] = Memo
ASKER
MAYBE THIS is easier to read:
I get a compile errror line 5
strSQL = "INSERT INTO Projects ([Created By],[Status2],[Currency],[ProjectNo],[Project Name],[Start Date],[Notes]) " _
& "VALUES ('" & [TempVars]![CurrentUserID] & "'," _
& 7 & "," _
& DLookup("CurrencyID", "tblCurrencyExchange", "[Currency] = '" & Me.txtCur & "'") & "," _
& '?' & "," _
& 'LC Ref: (but not needed so delete it after appending if want): ' & '" & Me.txtLCRef & "'," _
& #" & Format(Date, "m\/d\/yyyy") & "#," _
& "'****APPENDED Dnb*****: " & Format(Date, "m\/d\/yyyy") & "')"
I get a compile errror line 5
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
dang I thought this was going to be easy. Sorry.
I get error 3421 - Data type conversion error
let me know what is next.
I get error 3421 - Data type conversion error
let me know what is next.
ASKER
Not sure if makes a difference:
Status2 is Number with rowsource: SELECT tblStatus.ID, tblStatus.Status FROM tblStatus ORDER BY tblStatus.Status;
Status2 is Number with rowsource: SELECT tblStatus.ID, tblStatus.Status FROM tblStatus ORDER BY tblStatus.Status;
which line?
ASKER
where did you add the values for [TempVars]![CurrentUserID] ?
ASKER
Values for [TempVars]![CurrentUserID] is set in the login screen at startup:
Private Sub cmdLogin_Click()
On Error GoTo cmdLogin_Click_Err
If IsNull(cboCurrentEmployee) Then
Beep
MsgBox "You must first select an employee.", vbOKOnly, ""
Exit Sub
End If
TempVars.Add "CurrentUserID", Me.cboCurrentEmployee.Valu e
Private Sub cmdLogin_Click()
On Error GoTo cmdLogin_Click_Err
If IsNull(cboCurrentEmployee)
Beep
MsgBox "You must first select an employee.", vbOKOnly, ""
Exit Sub
End If
TempVars.Add "CurrentUserID", Me.cboCurrentEmployee.Valu
do the Login first, before running the codes...
ASKER
I tried....
I did this in the immediate window and gives Error:
?[CurrentUserID]
Error 2029
I did this in the immediate window and gives Error:
?[CurrentUserID]
Error 2029
ASKER
I dont know if I lose the temp variable at a certain point because it is "temp". ON another form I have, the [currentuserID] is correct.
try
? [TempVars]![CurrentUserID]
? [TempVars]![CurrentUserID]
ASKER
well I do have code in the same form that inserts the correct value for [TempVars]![CurrentUserID]
I am inserting on tblLetterOfCredit and not [Projects] but [Created By] has the same row source on tblLetterOfCredit as it does on [Projects].
here is a part of the code on another cmdbutton on same form:
strSQL = "INSERT INTO tblLetterOfCredit ([Created By],[LCNo] , [DateOfIssueSB], [FinalMaturity], " _
& "[Currency], [Amount], [Comments]) " _
& "VALUES ('" & [TempVars]![CurrentUserID] & "', '" & Me.txtLCRef & "'," _
I am inserting on tblLetterOfCredit and not [Projects] but [Created By] has the same row source on tblLetterOfCredit as it does on [Projects].
here is a part of the code on another cmdbutton on same form:
strSQL = "INSERT INTO tblLetterOfCredit ([Created By],[LCNo] , [DateOfIssueSB], [FinalMaturity], " _
& "[Currency], [Amount], [Comments]) " _
& "VALUES ('" & [TempVars]![CurrentUserID]
ASKER
? [TempVars]![CurrentUserID]
138
138 is correct
138
138 is correct
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
fyed: that was the solution. Tempvars worked too.
I cant say what specifically the issue was. I know of the confusion with using the Lookup feature in the table but I dont think that was the issue since I had it working before with no issue and I simply copied that dlookup that we worked on couple days ago.
I think it was either with item 2 or 3 above [project name], [start date]
Thought this was going to be a little easier. I dont like my questions to be like this...remember I am far from your level. thanks for hanging in with me.
Maybe I should split points?
I cant say what specifically the issue was. I know of the confusion with using the Lookup feature in the table but I dont think that was the issue since I had it working before with no issue and I simply copied that dlookup that we worked on couple days ago.
I think it was either with item 2 or 3 above [project name], [start date]
Thought this was going to be a little easier. I dont like my questions to be like this...remember I am far from your level. thanks for hanging in with me.
Maybe I should split points?
capricorn hung with you for most of this thread, while just stuck my head in at the beginning and the end. Award points accordingly.
Whenever I want to build a SQL string for an INSERT , UPDATE, or even a SELECT statement to be used in code, I use the function below:
Whenever I want to build a SQL string for an INSERT , UPDATE, or even a SELECT statement to be used in code, I use the function below:
Public Function fnWrap(WrapWhat As Variant, Optional WrapWith As Variant = """") As String
fnWrap = WrapWith _
& Replace(WrapWhat, WrapWith, WrapWith & WrapWith) _
& WrapWith
End Function
to wrap text strings in quotes and dates in the # sign. It is a little easier to read than the method you were trying above, because you don't have all of the embedded single quotes in your text. Given what we now know about the data types of each of your fields, from the recordset solution above, I think the following SQL string would also work:strCriteria = "[Currency] = '" & Me.txtCur & "'"
strSQL = "INSERT INTO Projects ([Created By],[Status2],[Currency],[ProjectNo]" _
& "[Project Name],[Start Date],[Notes]) " _
& "VALUES (" & [TempVars]![CurrentUserID] & "," _
& 7 & "," _
& DLookup("CurrencyID", "tblCurrencyExchange", strCriteria) & "," _
& "?" & "," _
& fnWrap("LC Ref: (but not needed so delete it after appending " _
& "if want): " & Me.txtLCRef) & "," _
& fnWrap(Date(), "#") & ", " _
& fnWrap("****APPENDED Dnb*****:" & Format(Date, "m\/d\/yyyy")) _
& ")"
ASKER
thank you for the expert help. Im sticking with the With statement. it works. the fnWrap and all is getting a little techy for me. :)
"',#" & Format(Date, "m\/d\/yyyy") & "'****APPENDED Dnb*****: "
You will notice that you are missing a closing # just before the APPEND text string. Try adding the closing #:
"',#" & Format(Date, "m\/d\/yyyy") & "#," & "'****APPENDED Dnb*****: "
I added the part that is in bold/underlined text.