I have the following code using the ConcatRelated function. the current sql works with 1 where condition but I can't figure out how to get the sql to work with 2 conditions. It works when use it in a query. I get issues and the code does not debug.
ItemsShpdInvSQL = "SELECT InvoiceAllShippedItems.ShipmentID, InvoiceAllShippedItems.ShipType, " _
& "InvoiceAllShippedItems.BillTo, InvoiceAllShippedItems.CustID AS Consignee, " _
& "InvoiceAllShippedItems.PayMethod, InvoiceAllShippedItems.PaidInFull, " _
& "First(InvoiceAllShippedItems.Units) AS Units, " _
& "'Freight Charges - Ref. WR: ' & (ConcatRelated('[WR]'," _
& "'[InvoiceAllShippedItems]','[BillTo] =' & [BillTo])) & " _
& "' - (' & Sum([Chargeable]) & ' ' & [Units] & ' " _
& ") - Number of Pieces: ' & [NoPieces] AS InvDetails, " _
& "Sum(InvoiceAllShippedItems.[# of Pieces]) AS NoPieces, " _
& "Sum(InvoiceAllShippedItems.Chargeable) AS Charge, " _
& "CustRate([custid],[ShipType]) AS CustomerRate, " _
& "IIf(([Charge])<6.1,20/[Charge],[CustomerRate]) AS RateMin " _
& "FROM InvoiceAllShippedItems " _
& "GROUP BY InvoiceAllShippedItems.ShipmentID, " _
& "InvoiceAllShippedItems.ShipType, InvoiceAllShippedItems.BillTo, " _
& "InvoiceAllShippedItems.CustID, InvoiceAllShippedItems.PayMethod, " _
& "InvoiceAllShippedItems.PaidInFull, InvoiceAllShippedItems.Units, " _
& "CustRate([custid],[ShipType]) " _
& "ORDER BY InvoiceAllShippedItems.BillTo;"
'& "CustRate([custid],[ShipType]);"
with this it works in a query but not in the code above:
'concatrelated("[WR]","InvoiceAllShippedItems","[BillTo]&[PayMethod] ='" & [BillTo] & [PayMethod] & "'")
I've used VBA to insert into an SQL table before but its always been using values in cells. I have three columns in my table where I need to add just a static value (so no cell reference).
The code I have so far is:
stSQL = "INSERT INTO Client_Notes " & _
"(ID, Category, RefID, Name, Notes, Date_Loaded, Latest) " & _
" VALUES (" & _
"'" & 1 & "', " & _
"'" & 1 & "', " & _
"'" & Sheets("Missing").ActiveCell.Offset(0, -10).Value & "', " & _
"'" & Sheets("Missing").ActiveCell.Offset(0, -9).Value & "', " & _
"'" & Sheets("Details").ActiveCell.Value & "', " & _
"'" & Date & "', " & "'" & _
"'" & 1 & "'" & _
")"
The error I keep getting is when trying to insert 1 as a value. I'm sure its straight forward but feel like I had tried every quote and comma combination going.
Thanks in advance
So the new code now looks like so, where I am getting Subscript Out Of Range:
stSQL = "INSERT INTO Client_Notes " & _
"(ID, Category, RefID, Name, Notes, Date_Loaded, Latest) " & _
" VALUES (" & _
"1, " & _
"1, " & _
"'" & Sheets("Missing").Range("L" & i).Offset(0, -10).Value & "', " & _
"'" & Sheets("Missing").Range("L" & i).Offset(0, -9).Value & "', " & _
"'" & Sheets("Details").Range("L" & i).Value & "', " & _
"'" & Date & "', " & _
"1)"
i cannot update the data, it says that data type mismatch in criteria experession
CurrentDb.Execute "UPDATE PC_Details " & _
" SET Serial_No=" & Me.txtNo & _
", PC_Brand='" & Me.txtBrand & "'" & _
", PC_Model='" & Me.txtModel & "'" & _
", Status='" & Me.txtStatus & "'" & _
", Description='" & Me.txtDesc & "'" & _
", Staff_ID='" & Me.txtID & "'" & _
" WHERE Serial_No=" & Me.txtNo.Tag
Do this to debug:
Dim SQL As String
SQL = "UPDATE PC_Details " & _
" SET Serial_No=" & Me.txtNo & _
", PC_Brand='" & Me.txtBrand & "'" & _
", PC_Model='" & Me.txtModel & "'" & _
", Status='" & Me.txtStatus & "'" & _
", Description='" & Me.txtDesc & "'" & _
", Staff_ID='" & Me.txtID & "'" & _
" WHERE Serial_No=" & Me.txtNo.Tag
Debug.Print SQL
CurrentDb.Execute SQL
Then study the resulting SQL and post it here.
If all values are present, one or more is text but is handled as number or vice versa.
I'm connecting to an AS/400 by an ODBC connection. I'm getting wacky errors when I try to insert and delete from the file. First, the format I've found for constructing a query stirng was like this:
"DELETE FROM <library>.<filename> WHERE <field> = <value>"
So, based on that, I wrote this:
"DELETE FROM RM#AVLIB.AV90909JWB WHERE MBR_NUM = " & mbr_num
It threw an error about not liking the DELETE, oddly enough, but I got it to go away if I removed the library altogether:
"DELETE FROM AV90909JWB WHERE MBR_NUM = " & mbr_num
I'm guessing it just didn't like the # symbol and worked without the library because my default library is the same one I'm using here. But now I'm getting an error in my INSERT that says:
ERROR [22003][Micro Focus][RUMBA Data Access][S1023934]Numeric value out of range. SQLCODE = -420
After running through all the values I'm passing, I didn't see any values that were longer than the field length so I'm not sure where this is coming from.
Here's my code as it sits now:
delQry = "DELETE FROM AV90301JWB WHERE MBR_CD = '" & MBR_CD & "' AND LOC_CD = '" & LOC_CD & "' AND PRP_ITM = '" & PRP_ITM & "'"
pushQry = "INSERT INTO AV90301JWB ( " & _
"MBR_NUM, " & _
"LOC_CD, " & _
"AVBLD_CLMT, " & _
"ADDRESS1, " & _
"ADDRESS2, " & _
"CITY, " & _
"STATE, " & _
"ZIPCODE, " & _
"AVBLD_DOS, " & _
"CNST_QLTY, " & _
"SEISMIC, " & _
"WIND, " & _
"AVBLD_DSC, " & _
"AVBLD_DSC1, " & _
"AVBLD_DSC2, " & _
"AVBLD_DSC3, " & _
"MISC_ADJ, " & _
"SEC_ID, " & _
"AVCOS_RC, " & _
"YR_BUILT, " & _
"NBR_STORY, " & _
"SQR_FT, " & _
"SUBCLASS, " & _
"OCC_CD1, " & _
"OCC_DSC1, " & _
"OCC_PCT1, " & _
"STORY_HT1, " & _
"OCC_CD2, " & _
"OCC_DSC2, " & _
"OCC_PCT2, " & _
"STORY_HT2, " & _
"OCC_CD3, " & _
"OCC_DSC3, " & _
"OCC_PCT3, " & _
"STORY_HT3, " & _
"OCC_CD4, " & _
"OCC_DSC4, " & _
"OCC_PCT4, " & _
"STORY_HT4, " & _
"OCC_CD5, " & _
"OCC_DSC5, " & _
"OCC_PCT5, " & _
"STORY_HT5, " & _
"HEAT_SYS, " & _
"COOL_SYS, " & _
"PWALL_EXT, " & _
"ROOF_MAT, " & _
"SPRINKLER, " & _
"MANL_FIRE, " & _
"AUTO_FIRE, " & _
"CNST_PCT1, " & _
"CNST_PCT2, " & _
"CNST_PCT3, " & _
"CNST_PCT4, " & _
"CNST_PCT5) " & _
"VALUES (" & _
"'" & MBR_NUM & "', " & _
"'" & LOC_CD & "', " & _
"'" & AVBLD_CLMT & "', " & _
"'" & ADDRESS1 & "', " & _
"'" & ADDRESS2 & "', " & _
"'" & CITY & "', " & _
"'" & STATE & "', " & _
"'" & ZIPCODE & "', " & _
"'" & AVBLD_DOS.ToShortDateString() & "', " & _
"'" & CNST_QLTY & "', " & _
"'" & SEISMIC & "', " & _
"'" & WIND & "', " & _
"'" & AVBLD_DSC & "', " & _
"'" & AVBLD_DSC1 & "', " & _
"'" & AVBLD_DSC2 & "', " & _
"'" & AVBLD_DSC3 & "', " & _
"'" & MISC_ADJ & "', " & _
"'" & SEC_ID & "', " & _
"" & Math.Round(AVCOS_RC, 2, MidpointRounding.AwayFromZero) & ", " & _
"'" & YR_BUILT & "', " & _
"'" & NBR_STORY & "', " & _
"'" & SQR_FT & "', " & _
"'" & SUBCLASS & "', " & _
"'" & OCC_CD1 & "', " & _
"'" & OCC_DSC1 & "', " & _
"'" & OCC_PCT1 & "', " & _
"'" & STORY_HT1 & "', " & _
"'" & OCC_CD2 & "', " & _
"'" & OCC_DSC2 & "', " & _
"'" & OCC_PCT2 & "', " & _
"'" & STORY_HT2 & "', " & _
"'" & OCC_CD3 & "', " & _
"'" & OCC_DSC3 & "', " & _
"'" & OCC_PCT3 & "', " & _
"'" & STORY_HT3 & "', " & _
"'" & OCC_CD4 & "', " & _
"'" & OCC_DSC4 & "', " & _
"'" & OCC_PCT4 & "', " & _
"'" & STORY_HT4 & "', " & _
"'" & OCC_CD5 & "', " & _
"'" & OCC_DSC5 & "', " & _
"'" & OCC_PCT5 & "', " & _
"'" & STORY_HT5 & "', " & _
"'" & HEAT_SYS & "', " & _
"'" & COOL_SYS & "', " & _
"'" & PWALL_EXT & "', " & _
"'" & ROOF_MAT & "', " & _
"'" & SPRINKLER & "', " & _
"'" & MANL_FIRE & "', " & _
"'" & AUTO_FIRE & "', " & _
"'" & CNST_PCT1 & "', " & _
"'" & CNST_PCT2 & "', " & _
"'" & CNST_PCT3 & "', " & _
"'" & CNST_PCT4 & "', " & _
"'" & CNST_PCT5 & "')"
Dim connectionString As String = ConfigurationManager.AppSettings("iSeriesConnString")
Dim insCommand As New OdbcCommand(pushQry)
Dim delCommand As New OdbcCommand(delQry)
Dim da As New OdbcDataAdapter
Using myConn As New OdbcConnection(connectionString)
insCommand.Connection = myConn
delCommand.Connection = myConn
myConn.Open()
da.InsertCommand = insCommand
da.DeleteCommand = delCommand
da.DeleteCommand.ExecuteNonQuery()
da.InsertCommand.ExecuteNonQuery()
End Using
Does anyone see something I'm missing or have any ideas about how to find my issue?
Thanks!
The standard ANSI SQL way of escaping invalid characters in an identifier or to escape an identifier which conflicts with a reserved keyword is to put it in double quotes:
DELETE FROM "RM#AVLIB".AV90909JWB WHERE ...
Obviously one of the values you are inserting or you are using in the where clause exceeds the range defined for that column. E.g. if a column has been defined as NUMERIC(2), you cannot insert 100.
Also I strongly urge you to use command parameters instead of string concatenation: See https://stackoverflow.com/a/2092851/880990
I am trying to make medical record application for my assignment. I found this error to edit data patient.
Please help and sorry for my bad grammar
Dim aksesedit As String = "Update tbpasien set " & _
"Nama_Pasien='" & txtnamapasien.Text & "', " & _
"Jenis_Kelamin='" & cmbjk.Text & "'," & _
"Tempat_Pasien='" & txttempatlahir.Text & "', " & _
"Tanggal_Lahir='" & tanggallahir.Text & "', " & _
"Alamat='" & txtalamat.Text & "', " & _
"Kelurahan_Desa='" & txtkeldesa.Text & "', " & _
"Kecamatan='" & txtkec.Text & "', " & _
"Kota_Kabupaten='" & txtkotakab.Text & "', " & _
"No_Telepon_HP='" & txtnotelp.Text & "', " & _
"Agama='" & cmbagama.Text & "', " & _
"Kewarganegaraan='" & cmbwarga.Text & "', " & _
"Status_Pernikahan='" & cmbstatus.Text & "', " & _
"Pekerjaan='" & txtpekerjaan.Text & "', " & _
"where No_RM='" & txtnorm.Text & "'"
cmd = New OleDbCommand(aksesedit)
cmd.Connection = conn
cmd.ExecuteNonQuery()
syntax error in update was on here
cmd.ExecuteNonQuery()
For "Tanggal_Lahir" i used datetimepicker, cmb=combobox, txt=textbox
Thanks
There should be no comma before the WHERE clause:
"Pekerjaan='" & txtpekerjaan.Text & "' " & _
"where No_RM='" & txtnorm.Text & "'"