I just faced a problem with my code.It raises an exception.This is the code.
conn = oSubPayItemDescription.GetDbConnection()
md = New OleDbCommand("SELECT [sub_pay_item_quantity].[quantity],[sub_pay_item_unit_rate].[rate] FROM " &
"[sub_pay_item_quantity],[sub_pay_item_unit_rate] WHERE [sub_pay_item_quantity].[sub item]=[sub_pay_item_unit_rate].[sub item] AND " &
"[sub_pay_item_quantity].[sub item]='" & subItem & "' AND [sub_pay_item_quantity].[bridge type]='" & bridgeType & "' " &
"AND [sub_pay_item_quantity].[span]='" & span & "'", conn)
data_reader = cmd.ExecuteReader()
If data_reader.HasRows = True Then
Do While data_reader.Read()
payItem = CDbl(data_reader.Item("pay item"))
subpayItem = CDbl(data_reader.Item("sub pay item"))
subItem = data_reader.Item("sub item")
unit = data_reader.Item("unit")
bridgeType = data_reader.Item("bridge type")
span = (data_reader.Item("span").ToString())
quantity = CDbl(data_reader.Item("quantity"))
rate = CDbl(data_reader.Item("rate"))
RichTextBox1.AppendText(payItem & vbTab & vbTab & " " & " " & subpayItem & vbTab & vbTab & subItem & vbTab & vbTab & " " & _
unit & vbTab & vbTab & " " & " " & " " & " " & bridgeType & vbTab & vbTab & " " & span & vbTab & _
"" & vbTab & " " & quantity & vbTab & rate & vbNewLine)
Loop
Else
MsgBox("Unit rate does not exist", vbCritical, "Bridge Construction Cost Estimate")
End If
It raises the exception when it reaches the do while loop indicating at pay item.
So the specified name does not exist in the DataReader as the documentation suggests:
IndexOutOfRangeException: No column with the specified name was found
and i cannot see this column in your query. You are selecting only quantity and rate.
Related
In Access 2010 I have tables, e.g. Employee(Pracownicy). I can update the data in the table using the subform and the update button.
Updating the data in the subform automatically generates an Outlook mail containing the data in the updated record.
I need to change font color for updated data in the mail body.
The code to update the data and generate e-mail:
Private Sub cmdUpdate2_Click()
CurrentDb.Execute "update Pracownicy" & _
" SET Identyfikator='" & Me.txtID & "'" & _
", Imie='" & Me.txtImie & "'" & _
", Nazwisko ='" & Me.txtNazwisko & "'" & _
", Wiek ='" & Me.txtWiek & "'" & _
", Data_urodzenia ='" & Me.txtData & "'" & _
", Miejsce_urodzenia ='" & Me.txtMiejsce & "'" & _
", Miejscowosc ='" & Me.txtMiejscowosc & "'" & _
", Plec ='" & Me.txtPlec & "'" & _
" where Identyfikator='" & Me.txtID & "'"
'------------------------------------SEND EMAIL----------------------
'Dim varName As Variant
'Dim strUCC As String
Dim varSubject As Variant
Dim varBody As Variant
Dim Poczta As Object
Dim MojMail As Object
On Error Resume Next
'varName = ""
varSubject = "Employer List "
varBody = "Hello" & _
"<br><br>Employer List: " & _
"<br><br><B>Identyfikator:</B> " & Me.txtID & " " & _
"<br><B>Imie:</B> " & Me.txtImie & " " & _
"<br><B>Nazwisko:</B> " & Me.txtNazwisko & " " & _
"<br><B>Wiek:</B> " & Me.txtWiek & " " & _
"<br><B>Data urodzenia:</B> " & Me.txtData & " " & _
"<br><B>Miejsce urodzenia:</B> " & Me.txtMiejsce & " " & _
"<br><B>Miejscowosc:</B> " & Me.txtMiejscowosc & " " & _
"<br><B>Plec:</B> " & Me.txtPlec & " "
Set Poczta = CreateObject("outlook.application")
Set MojMail = Poczta.createitem(0)
With MojMail
'.To =
'.BCC =
.subject = varSubject
'.ReadReceiptRequested = True
'.originatorDeliveryReportRequested = True
.htmlbody = varBody & "<br>"
.display
'.send
End With
Set Poczta = Nothing
Set MojMail = Nothing
If Err.Number <> 0 Then
MsgBox ("Atention")
End If
On Error GoTo 0
'------------------------------------------------------------------------
DoCmd.Close
MsgBox ("End Update")
End Sub
I think this becomes more of an HTML question rather than VBA. Try adding a FONT tag to the following line and see if that works for you.
"<br><br><B><font color="red">Identyfikator:</font></B> " & Me.txtID & " " & _
I have the below Excel 2010 VBA that is in two parts. The first portion checks if a CheckBox on a sheet is checked, if it then it adds the value of a specified cell to the sample_descriptor.txt in the portion below that. Currently I am getting a
subscript out of range error
and am not sure if this is the best way to accomplish this task. Thank you :). The value for comment1 is F9, comment2 is F10, comment3 is F11, and comment4 is F12
VBA
' ADD COMMENT IF ANY '
If CheckBox17.Value = True Then
Worksheets("Sheet1").Range("F9") = ActiveSheet.Range("F9").Value
Else
Worksheets("Sheet1").Range("F9") = "No Issues"
End If
If CheckBox17.Value = True Then
Worksheets("Sheet1").Range("F10") = ActiveSheet.Range("10").Value
Else
Worksheets("Sheet1").Range("F10") = "No Issues"
End If
If CheckBox17.Value = True Then
Worksheets("Sheet1").Range("F11") = ActiveSheet.Range("F11").Value
Else
Worksheets("Sheet1").Range("F11") = "No Issues"
End If
If CheckBox17.Value = True Then
Worksheets("Sheet1").Range("F12") = ActiveSheet.Range("F12").Value
Else
Worksheets("Sheet1").Range("F12") = "No Issues"
End If
Unload Me
'WRITE TO SAMPLE DESCRIPTOR.txt '
Open MyDirectory & "sample_descriptor.txt" For Output As #1
Print #1, "Experiment Sample" & vbTab & "Control Sample" & vbTab & "Display Name" & vbTab & "Gender" & vbTab & "Control Gender" & vbTab & "Spikein" & vbTab & "Location" & vbTab & "Barcode" & vbTab & "Medical Record" & vbTab & "Date of Birth" & vbTab & "Order Date"
Print #1, "2571683" & MyBarCode & "_532Block1.txt" & vbTab & "2571683" & MyBarCode & "_635Block1.txt" & vbTab & ActiveSheet.Range("B8").Value & " " & ActiveSheet.Range("B9").Value & vbTab & ActiveSheet.Range("B10").Value & vbTab & ActiveSheet.Range("B5").Value & vbTab & Split(ActiveSheet.Range("B11").Value, " [")(0) & vbTab & ActiveSheet.Range("B12").Value & vbTab & "2571683" & MyBarCode & vbTab & ActiveSheet.Range("C200").Value & vbTab & ActiveSheet.Range("D200").Value & vbTab & ActiveSheet.Range("E200").Value & IIf(Sheet.CheckBox17, vbTab & ActiveSheet.Range("F9").Value, "")
Print #1, "2571683" & MyBarCode & "_532Block2.txt" & vbTab & "2571683" & MyBarCode & "_635Block2.txt" & vbTab & ActiveSheet.Range("C8").Value & " " & ActiveSheet.Range("C9").Value & vbTab & ActiveSheet.Range("C10").Value & vbTab & ActiveSheet.Range("C5").Value & vbTab & Split(ActiveSheet.Range("C11").Value, " [")(0) & vbTab & ActiveSheet.Range("C12").Value & vbTab & "2571683" & MyBarCode & vbTab & ActiveSheet.Range("C201").Value & vbTab & ActiveSheet.Range("D201").Value & vbTab & ActiveSheet.Range("E201").Value & IIf(Sheet.CheckBox17, vbTab & ActiveSheet.Range("F10").Value, "")
Print #1, "2571683" & MyBarCode & "_532Block3.txt" & vbTab & "2571683" & MyBarCode & "_635Block3.txt" & vbTab & ActiveSheet.Range("D8").Value & " " & ActiveSheet.Range("D9").Value & vbTab & ActiveSheet.Range("D10").Value & vbTab & ActiveSheet.Range("D5").Value & vbTab & Split(ActiveSheet.Range("D11").Value, " [")(0) & vbTab & ActiveSheet.Range("D12").Value & vbTab & "2571683" & MyBarCode & vbTab & ActiveSheet.Range("C202").Value & vbTab & ActiveSheet.Range("D202").Value & vbTab & ActiveSheet.Range("E202").Value & IIf(Sheet1.CheckBox17, vbTab & ActiveSheet.Range("F11").Value, "")
Print #1, "2571683" & MyBarCode & "_532Block4.txt" & vbTab & "2571683" & MyBarCode & "_635Block4.txt" & vbTab & ActiveSheet.Range("E8").Value & " " & ActiveSheet.Range("E9").Value & vbTab & ActiveSheet.Range("E10").Value & vbTab & ActiveSheet.Range("E5").Value & vbTab & Split(ActiveSheet.Range("E11").Value, " [")(0) & vbTab & ActiveSheet.Range("E12").Value & vbTab & "2571683" & MyBarCode & vbTab & ActiveSheet.Range("C203").Value & vbTab & ActiveSheet.Range("D203").Value & vbTab & ActiveSheet.Range("E203").Value & IIf(Sheet1.CheckBox17, vbTab & ActiveSheet.Range("F12").Value, "")
Close #1
file format
x
x 1 2 3 4
x 11 22 33 44
x --- --- --- ---
x Male Male Female Male
x --- --- --- ---
x 1 2 3 4 Please check the box to add comment
x 1111 2222 3333 4444 (checkbox17)
x xxx,xxx xxx,xxx xxx,xxx xxx,xxx comment1
x Male Male Female Male comment2
x xx xx xx xx comment3
x x x x x comment4
You must change:
ActiveSheet.Range("10").Value
into:
ActiveSheet.Range("F10").Value
But you can shorten down your code to:
If CheckBox17 Then
Worksheets("Sheet1").Range("F9:F12").value = ActiveSheet.Range("F9:F12").value
Else
Worksheets("Sheet1").Range("F9:F12") = "No Issues"
End If
I have data in dataset which I am loopping to build up data for the email the data is as follows but I am using the following to produce the email using tabs but it doesnt see very iffiencet i can only use plain text is their a better way to get it to format nicer like using the datatable sizes or something
Dim dataForEmail As String = ""
Dim msg As String = ""
msg = "The Following Deliverys where processed for the Following Ordernumbers at " & DateTime.Now.ToString() & Chr(13)
dataForEmail = "Order Number" & vbTab & "BarCode" & vbTab & vbTab & vbTab & "Description" & vbTab & vbTab & vbTab & vbTab & vbTab & "Brand" & vbTab & vbTab & vbTab & "Size" & vbTab & "Colour" & vbTab & "Price" & vbTab & "RRP" & vbTab & vbTab & vbTab & "Qty" & Chr(13)
Dim totalcost As Decimal
If Not IsNothing(results) AndAlso Not IsNothing(results.Rows) _
AndAlso results.Rows.Count > 0 Then
For Each thisRow As DataRow In results.Rows
CreateDeliveryIncFileForGemini(thisRow)
totalcost = totalcost + thisRow.Item("RRPPrice")
dataForEmail = dataForEmail & BuildReportFoEmail(thisRow)
connection.ExecuteNonQuerySql(scriptBuilder.SetDeliveryStatus(2, 1, thisRow.Item("r3DeliveryId")))
Next
connection.ExecuteNonQuerySql(scriptBuilder.SetDeliveryStatus(1, 0))
dataForEmail = dataForEmail & vbCrLf & "Total Price " & totalcost.ToString()
SendEmailViaWebService(dataForEmail, cfb.EmailForDeliverys, cfb.FullNameForEmailSubject, msg)
End If
CloseConnection()
I am new to using Access 2010. I wish to execute the following sql update statement, but I have problems with the syntax. The table is called "Forecasts", and users will edit & update the qty forecasted.
Problem - The table fieldnames are 2014_1, 2014_2, 2014_3 ... to represent the different months, stored in an array. I have done abit of research and I believe the way to dynamically do this is:
Dim sqlString As String
sqlString = "UPDATE Forecasts " & _
" SET Branch_Plant=" & Me.txtBranch_Plant & _
", Item_Number_Short='" & Me.txtItem_Number_Short & "'" & _
", Description='" & Me.txtDescription & "'" & _
", UOM='" & Me.txtUOM & "'" & _
", Estimated_Cost=" & Me.txtEstimated_Cost & _
", Requesting_Business_Unit='" & Me.txtRequesting_Business_Unit & "'" & _
", End_Customer='" & Me.txtEnd_Customer & "'" & _
", Project='" & Me.txtProject & "'" & _
", Forecasts." & "[" & arrMonthToDisplay(0) & "]" = " & Me.txtProjectedJanVolume " & _
" WHERE ID =" & Me.txtID.Tag
MsgBox ("This is the output: " & sqlString)
CurrentDb.Execute sqlString
It was working fine until this line was added
Forecasts." & "[" & arrMonthToDisplay(0) & "]" = " & Me.txtProjectedJanVolume
The msgbx output now shows: "False". Whats wrong with sqlString?
Please help! Thank you very much.
", Forecasts.[" & arrMonthToDisplay(0) & "] = " & Me.txtProjectedJanVolume & _
" WHERE ID =" & Me.txtID.Tag
You compare string to string.
Change
", Forecasts." & "[" & arrMonthToDisplay(0) & "]" = " & Me.txtProjectedJanVolume " &
to
", Forecasts." & "[" & arrMonthToDisplay(0) & "] = " & " Me.txtProjectedJanVolume " &
When I try to write text to a file, I get an error saying "FormatException was unhandled"
Here's the code:
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim ChampPath As String = FolderBrowserDialog1.SelectedPath & "\League of Legends\Config\Champions"
Dim NamePath As String = ChampPath & "\" & SelectChampion.Text
Dim FilePath As String = NamePath & "\" & SelectChampion.Text & ".json"
Dim Map As String
Dim Mode As String
System.IO.Directory.CreateDirectory(NamePath)
System.IO.File.Create(FilePath).Dispose()
If (SelectMap.Text = "Any") Then
Map = "any"
ElseIf (SelectMap.Text = "Summoners Rift") Then
Map = "1"
ElseIf (SelectMap.Text = "Twisted Treeline") Then
Map = "10"
ElseIf (SelectMap.Text = "Crystal Scar") Then
Map = "8"
ElseIf (SelectMap.Text = "Proving Grounds") Then
Map = "3"
End If
If (SelectMode.Text = "Any") Then
Mode = "any"
ElseIf (SelectMode.Text = "Classic") Then
Mode = "CLASSIC"
ElseIf (SelectMode.Text = "Dominon") Then
Mode = "ODIN"
ElseIf (SelectMode.Text = "Proving Grounds") Then
Mode = "ARAM"
End If
If (System.IO.File.Exists(FilePath)) Then
Using Writer As StreamWriter = New StreamWriter(FilePath)
Writer.Write("{" & vbNewLine &
" ""champion"":""" & SelectChampion.Text & """," & vbNewLine &
" ""title"":""" & TitleBox.Text & "", " " & vbNewLine &
" ""type"":""" & TypeBox.Text & "", " " & vbNewLine &
" ""map"":""" & Map & "", " " & vbNewLine &
" ""mode"":""" & Mode & "", " " & vbNewLine &
" ""priority""" & SelectPriority.Text & "", " " & vbNewLine &
" ""blocks"":[ " & vbNewLine &
"{" & vbNewLine &
" ""type"":""starting"", " & vbNewLine &
" ""items"":[ " & vbNewLine &
"{" & vbNewLine &
" ""id"":""1001"", " & vbNewLine &
" ""count"":1 " & vbNewLine &
"}," & vbNewLine &
"{" & vbNewLine &
" ""id"":""3010"", " & vbNewLine &
" ""count"":3 " & vbNewLine &
"}" & vbNewLine &
"]" & vbNewLine &
"}," & vbNewLine &
"{" & vbNewLine &
" ""type"":""essential"", " & vbNewLine &
" ""items"":[ " & vbNewLine &
"{" & vbNewLine &
" ""id"":""3001"", " & vbNewLine &
" ""count"":1 " & vbNewLine &
"}," & vbNewLine &
"{" & vbNewLine &
" ""id"":""3089"", " & vbNewLine &
" ""count"":1 " & vbNewLine &
"}" & vbNewLine &
"]" & vbNewLine &
"}," & vbNewLine &
"{" & vbNewLine &
" ""type"":""offensive"", " & vbNewLine &
" ""items"":[ " & vbNewLine &
"{" & vbNewLine &
" ""id"":""3100"", " & vbNewLine &
" ""count"":1 " & vbNewLine &
"}," & vbNewLine &
"{" & vbNewLine &
" ""id"":""3128"", " & vbNewLine &
" ""count"":1 " & vbNewLine &
"}," & vbNewLine &
"{" & vbNewLine &
" ""id"":""3135"", " & vbNewLine &
" ""count"":1 " & vbNewLine &
"}" & vbNewLine &
"]" & vbNewLine &
"}," & vbNewLine &
"{" & vbNewLine &
" ""type"":""defensive"", " & vbNewLine &
" ""items"":[ " & vbNewLine &
"{" & vbNewLine &
" ""id"":""3140"", " & vbNewLine &
" ""count"":1 " & vbNewLine &
"}," & vbNewLine &
"{" & vbNewLine &
" ""id"":""3157"", " & vbNewLine &
" ""count"":1 " & vbNewLine &
"}" & vbNewLine &
"]" & vbNewLine &
"}" & vbNewLine &
"]" & vbNewLine &
"}")
End Using
End If
End Sub
I can't find where the error is actually coming from...
The text also needs to be formatted like it is, with the quotes and what not. Thanks for any help.
Assumed VB Net .. Better you change like this
Writer.Write("{" & vbNewLine & _
" champion : " & SelectChampion.Text & "," & vbNewLine & _
" title : " & TitleBox.Text & "," & vbNewLine & _
" type : " ........
...... etc