syntax error at insert into - ms-access

i need to insert some informations from a form to a table fields, i tried this code:
Dim sql As String
sql = " insert into récapRELAIS( Région, Groupe, Agence, N°personne,
Nom du client, N°prêt, Durée, Nature du prêt, Encours client)
Values ("
& Me.Region & " , " & Me.Groupe & " , "
& Me.Agence & " , " & Me.Num_Personne & " , "
& Me.Nom_client & " , " & Me.Num_Contrat & " , "
& Me.Montant_prêt & ", " & Me.Durée_prêt & " ,"
& Me.Nature_prêt & " , " & Me.Encours & "); "
DoCmd.RunSQL sql
but it doesn't work, it says that i have an error type 3134

The problem are most likely your field names with spaces.
Solution: Surround with square brackets - [ ], like this:
insert into récapRELAIS( Région, Groupe, Agence, [N°personne],
[Nom du client], [N°prêt], Durée, [Nature du prêt], [Encours client])
I am also not sure if the ° sign is working.
In general, I advice you to not take spaces or special characters or diacritics like ê è é for database field names.
Formatting and pretty display should take place in the user interface; but the database is more a programming environment, and there, it's better to just use the basic characters A-Z and 0-9.

Related

SSRS expression not displaying the right values

I'm trying to run the following expression:
=IIF((Fields!EntryFirstName.Value = " ") And (Fields!EntryLastName.Value = " " ),
"Team:" & Fields!TeamName.Value, Fields!EntryOrder.Value & " . "
& Fields!EntryFirstName.Value & " " & Fields!EntryLastName.Value)
The table that the following is looking at is this one :
However running the above expression will only return the following ( where EntryFirst name is the column EntryfirstName and so on):
Fields!EntryOrder.Value & " . "
& Fields!EntryFirstName.Value & " " & Fields!EntryLastName.Value
for the whole report ( this one expression is part of a row group, if that would change anything)

MS Access Tag property - how its identifying update and insert operation?

I trying to create Add,update,Delete operation on MS Access form.I found this code on internet where Insert and update is happening on the same button. I am not getting what is exactly happening in below line and how it's identifying it is for update or insert.
Not getting following line : = Me.txtid.Tag & "" = ""
Please find below code which works perfect as per requirement.
'When we click on button Add there are two options
'1. for insert
'2. for update
If Me.txtid.Tag & "" = "" Then
' this is for insert new
' add data in table
CurrentDb.Execute "insert into student(stdid,stdname,gender,phone,address)" & _
" values(" & Me.txtid & ",' " & Me.txtname & " ',' " & Me.cmbgender & " ','" & _
Me.txtphone & "', '" & Me.txtaddress & "')"
'refresh data in list on form
subform_student.Form.Requery
Else
CurrentDb.Execute "UPDATE student " & _
" set stdid = " & Me.txtid & _
", stdname = '" & Me.txtname & "' " & _
", gender = '" & Me.cmbgender & " ' " & _
", phone = ' " & Me.txtphone & " ' " & _
", address = ' " & Me.txtphone & " ' " & _
" WHERE stdid = " & Me.txtid.Tag
End If
The .Tag property is a general-purpose string property of every form and control object in VBA/VB6. It is provided as a place for developers to "put stuff" to support the operation of their applications.
The original code from which you copied your sample must have written a value to Me.txtid.Tag when the record was loaded (e.g., perhaps in the form's Current event) to indicate whether the record is an existing record or a new record (empty="new", non-empty="existing"). The line
If Me.txtid.Tag & "" = "" Then
simply checks to see if the .Tag property is empty, and then performs the INSERT or UPDATE accordingly.
BTW, re:
below code which works perfect as per requirement
No, it doesn't. Try adding a record where [stdname] is Tam O'Shanter and see for yourself. You should ditch the dynamic SQL and use one of
a bound form (as Gustav suggests),
a parameterized query, or
a recordset update.
Forget/remove all this code and bind the form to table Student to make this all happen automatically.
If a bound form is not familiar to you, browse for a tutorial for "Beginning with Microsoft Access" or the like.

A character is cut off when data from a textfield in a form containing two dots has to be inserted into a table

When I want to insert data from a form into a table in MS Access 2010 using the following code I receive a runtime error '3075'.
It says: Syntax error in the query experession '123.11.1' even though the text field "AbsErst" contained '123.11.11'. When I enter something without dots or with only one dot into "AbsErst" the code runs perfectly and inserts the data into the table.
I looked for other questions with the same error code but did not find the same issue there.
Looking forward for your answers or ideas
Henrik
Private Sub cmdStore_Click()
CurrentDb.Execute "INSERT INTO tblAbschnitt(INST_F,GDE_F,ABT_F,RW_F,Erst,Stand) " & " VALUES(" & _
Me.cboInst & "," & Me.cboGem & "," & Me.cboAbt & "," & Me.cboRW & "," & Me.AbsErst & "," & Me.absStan & ")"
End Sub
If you want to insert text into a table (and '123.11.1' is text), then you have to enclose it with single quotes in the SQL statement.
CurrentDb.Execute "INSERT INTO tblAbschnitt" & _
"(INST_F,GDE_F,ABT_F,RW_F,Erst,Stand) " & _
" VALUES(" & Me.cboInst & _
"," & Me.cboGem & _
"," & Me.cboAbt & _
"," & Me.cboRW & _
",'" & Me.AbsErst & "'" & _
"," & Me.absStan & _
")"
Do this not only with Me.AbsErst but with all text columns. You have to make sure for all those columns that the value to be inserted does not contain any single quotes themselves. They'd need to be escaped by another single quote. (Cue: SQL Injection)
All this could be probably done much easier and safer if you do not use an INSERT statement but something like this:
With CurrentDb.OpenRecordset("tblAbschnitt")
.AddNew
.Fields("INST_F") = Me.cboInst
.Fields("GDE_F") = Me.cboGem
.Fields("ABT_F") = Me.cboAbt
.Fields("RW_F") = Me.cboRW
.Fields("Erst") = Me.AbsErst
.Fields("Stand") = Me.absStan
.Update
End With
This way all the escaping and single quotes are handled automatically.

Too few parameters, expected 1? error access

I am getting the above error whilst running this commmand:
CurrentDb.Execute "UPDATE VolunteerDetails " & _
" SET FirstName=" & Me.frst_Name_txt & _
", LastName='" & Me.lst_Name_txt & "'" & _
", PostalCode='" & Me.pst_Code_txt & "'" & _
" WHERE VolsID=" & Me.vol_ID_txt
Can anyone explain why?
Thanks!
I think your problem is in the FirstName value. It seems to be a string and so you need to put your value inside single quotes
CurrentDb.Execute "UPDATE VolunteerDetails " & _
" SET FirstName='" & Me.frst_Name_txt & "'" & _
", LastName='" & Me.lst_Name_txt & "'" & _
", PostalCode='" & Me.pst_Code_txt & "'" & _
" WHERE VolsID=" & Me.vol_ID_txt
Said that, please read about Sql Injection and Parameterized queries. Your code, as is, it is very weak and could fail simply if someone types a LastName like O'Malley (the single quote breaks your string concatenation)
As pointed by a comment above, I suppose that these variables are not TextBoxes but just string variables. If these are TextBoxes then, the value to set the field to comes from the Text property of the TextBox. Something like
" SET FirstName='" & Me.frst_Name_txt.Text & "'"

Trying to replace a certain character in SSRS

I am trying to replace a the charater 0 when pulling through a report. I have entered the expression below and when I run my report I get a #Error any hints on what I am doing wrong?
Thanks
=IIf(Fields!HomeAddress2.Value & " " & Fields!HomeAddress3.Value & " " &Fields!HomeAddress4.Value = 0, Fields!HomeAddress2.Value & " " & Fields!HomeAddress3.Value & " " &Fields!HomeAddress4.Value, "")
Isn't it similar to NULL?
Maybe you can try ISNULL( <your expression>, " ")