Solved Where Is Syntax Error In My Code - Run-time Error 3075

Ashfaque

Search Beautiful Girls from your town for night
Local time
Today, 17:59
Joined
Sep 6, 2004
Messages
894
Hello,
For some reason, I would like to change company name (in 2 languages) and CR (Certificated of Registraton) in tble T_JobOffer with condtion if a particular CNo (candidate number) is what is at present on the form.

In compilation no error found but at execution it produces Error 3075.

Code:
Dim strSQL As String
strSQL = "INSERT INTO T_JobOffer " & _
"(CECompany, CACompany, CCrNumber) VALUES(" & Me!CboSelectNewCo.Column(0) & ", " & Me!CboSelectNewCo.Column(1) & ", " & Me!CboSelectNewCo.Column(2) & _
" Where (T_JobOffer.CNO)= " & Forms!AA!CNo & ")"
DoCmd.RunSQL strSQL

Please help.
 
It is likely there is a missing operator in the query, check the query or copy and paste in query design view to run it.
 
It is vba code which placed onclick event of a command btn on a continues form. I want to shift selected employees from that continues form and and store in relevent tble T_JobOffer.

How to copy it in query n run?
 
I want to shift selected employees from that continues form and and store in relevent tble T_JobOffer.
By shift, do you mean move/delete from the continuous forms data source and insert into tble T_jobOffer?
 
By shift, do you mean move/delete from the continuous forms data source and insert into tble T_jobOffer?
The Continuous form is just to bring the data on screen and from there it will shift to tble T_JobOffer.

The data source of this continuous form is a query that is based on tble T_JobOffer.
 

Attachments

  • AA.jpg
    AA.jpg
    68.3 KB · Views: 302
The Continuous form is just to bring the data on screen and from there it will shift to tble T_JobOffer.

The data source of this continuous form is a query that is based on tble T_JobOffer.
Am a bit lost here, the continous form's record source is a query based on table T_JobOffer, which means its still getting data from table T_JobOffer, so how do u move data from same table to same table?
 
Am a bit lost here, the continous form's record source is a query based on table T_JobOffer, which means its still getting data from table T_JobOffer, so how do u move data from same table to same table?
Yes, you are correct but the limited data appearing on this continuous form is thru query and I am just updating 3 fields data in the tble where the CNo number is same as that appears on the form. I am replacing name of company and its CR number of the same record. Isnt it possible?

Or it would be better to call the data in unbound text boxes along with CNo and then replace the company name etc ?
 
i think you misplaced the last ")" in your query string:
Code:
Dim strSQL As String
strSQL = "INSERT INTO T_JobOffer " & _
"(CECompany, CACompany, CCrNumber) VALUES(" & Me!CboSelectNewCo.Column(0) & ", " & Me!CboSelectNewCo.Column(1) & ", " & Me!CboSelectNewCo.Column(2) & ") " & _
"Where (T_JobOffer.CNO)= " & Forms!AA!CNo
DoCmd.RunSQL strSQL
 
Please share the following syntax

1. The select query
2. The update query
 
Just a guess, but if CECompany and CACompany are string types, you need to enclose them in single quotes, like this (in red):

VALUES('" & Me!CboSelectNewCo.Column(0) & "', '" & Me!CboSelectNewCo.Column(1) & "', "
 
i think you misplaced the last ")" in your query string:
Code:
Dim strSQL As String
strSQL = "INSERT INTO T_JobOffer " & _
"(CECompany, CACompany, CCrNumber) VALUES(" & Me!CboSelectNewCo.Column(0) & ", " & Me!CboSelectNewCo.Column(1) & ", " & Me!CboSelectNewCo.Column(2) & ") " & _
"Where (T_JobOffer.CNO)= " & Forms!AA!CNo
DoCmd.RunSQL strSQL
Still same error
 
Just a guess, but if CECompany and CACompany are string types, you need to enclose them in single quotes, like this (in red):

VALUES('" & Me!CboSelectNewCo.Column(0) & "', '" & Me!CboSelectNewCo.Column(1) & "', "
Yes these both are string type. and CR number is number.
 
you can use Querydef to insert:
Code:
With Currentdb.CreateQuerydef("", "INSERT INTO T_JobOffer " & _
"(CECompany, CACompany, CCrNumber) VALUES(p1, p2, p3) Where (T_JobOffer.CNO)=p4)")
    .Parameters(0)=Me!CboSelectNewCo.Column(0)
    .Parameters(1)=Me!CboSelectNewCo.Column(1)
    .Parameters(2)=Me!CboSelectNewCo.Column(2) 
    .Parameters(3)=Forms!AA!CNo
    .Execute
End With
 
Also I like to know if my process is correct or not. Bcz as raised by oleronesoftwares, should I bring the data in unbound form first and then replace few fields?

Please advise
 
Yes these both are string type. and CR number is number.
Then you need to apply the single quotes (') around string data types. I didn't see them in your original code.
You can do a Debug.Print or Msgbox the strSQL to double check before execute. I make this kind of careless mistakes very often.
 
you can use Querydef to insert:
Code:
With Currentdb.CreateQuerydef("", "INSERT INTO T_JobOffer " & _
"(CECompany, CACompany, CCrNumber) VALUES(p1, p2, p3) Where (T_JobOffer.CNO)=p4)")
    .Parameters(0)=Me!CboSelectNewCo.Column(0)
    .Parameters(1)=Me!CboSelectNewCo.Column(1)
    .Parameters(2)=Me!CboSelectNewCo.Column(2)
    .Parameters(3)=Forms!AA!CNo
    .Execute
End With
 

Attachments

  • Error.jpg
    Error.jpg
    15.4 KB · Views: 341
sorry, you cannot Insert with Criteria, you can only do this in Update Query.
 
You can do a Debug.Print or Msgbox the strSQL to double check before execute. I make this kind of careless mistakes very often.
With the O/P having over 800 posts, you'd hope they knew that by now? :(
 
I tried changing code with UPDATE query....

Code:
Dim strSQL As String
strSQL = "UPDATE T_JobOffer " & _
"SET [CECompany]= '" & Forms!F_SaudizationPercent!CECompany & "', [CACompany]='" & Forms!F_SaudizationPercent!CACompany & "', [CCrNumber]='" & Forms!F_SaudizationPercent!CACompany & "', " & Forms!F_SaudizationPercent!CCrNumber & ") " & _
"Where (T_JobOffer.CNO)= " & Forms!F_SaudizationPercent!CNo
DoCmd.RunSQL strSQL

It produced now Runtime error 3144...Syntax error in UPDATE statement....
 
Last edited:
remove the Last ")" and replace it with just " " (space).
Code:
strSQL = "UPDATE T_JobOffer " & _
"SET [CECompany]= '" & Forms!F_SaudizationPercent!CECompany & "', [CACompany]='" & Forms!F_SaudizationPercent!CACompany & "', [CCrNumber]='" & Forms!F_SaudizationPercent!CCrNumber & "' " & _
"Where (T_JobOffer.CNO)= " & Forms!F_SaudizationPercent!CNo
 

Users who are viewing this thread

Back
Top Bottom