I'm receiving error message "Syntax error missing operator in query expression" any help you can provide is appreciated.


Private Sub btnEmailCat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEmailCat.Click
Dim SQLStmt, EmailAddress, SubjectLine, BodyText, CATDateString, DollarsAndCents, NoDecimal As String
Dim CATCounter As Integer
Dim GSIdNum, GSIdHash As Long
Dim Cnxn As New OleDbConnection( _
"Provider=Microsoft.JET.OLEDB.4.0;" _
& "Data Source=DB.mdb")
Cnxn.Open()
If Cnxn.State <> ConnectionState.Open Then
MsgBox("Unable to connect to the database...", MsgBoxStyle.Critical)
End
End If
SQLStmt = "SELECT Id, Descr, Price from GS WHERE Ledger = 4010"
Debug.Write("SQLStmt=" & SQLStmt)
Dim cmdSearch As New OleDbCommand(SQLStmt, Cnxn)
Dim CatEntries As OleDbDataReader = cmdSearch.ExecuteReader
If Not CatEntries.Read Then
MsgBox("No records were found with Ledger 4010")
Else
CATCounter = 0
GSIdHash = 0
CATDateString = Format(Now(), "yyyyMMddHHmmss")
EmailAddress = "ledgerengine@info465.net"
SubjectLine = "*!*!9999*" & CATDateString
BodyText = "CAT*9999*" & CATDateString & vbCrLf
Do
CATCounter += 1
DollarsAndCents = Format(CatEntries.Item("Price"), "0.00")
NoDecimal = Microsoft.VisualBasic.Left(DollarsAndCents, Len(DollarsAndCents) - 3) & _
Microsoft.VisualBasic.Right(DollarsAndCents, 2)
BodyText &= "ITEM*" & CatEntries.Item("Id") & "*" & CatEntries.Item("Descr") & _
"*" & NoDecimal & vbCrLf
GSIdNum = Val(CatEntries.Item("Id"))
GSIdHash += GSIdNum
Loop Until Not CatEntries.Read
BodyText &= "ECAT*" & CATCounter + 2 & "*" & GSIdHash
Dim TheEmail As New System.Net.Mail.MailMessage
TheEmail.To.Add("gs9191@info465.net")
TheEmail.From = New MailAddress("1spice@vcu.edu")
TheEmail.Subject = SubjectLine
MsgBox("Body Text =" & BodyText)
TheEmail.Body = BodyText
Dim SMTPClient As New SmtpClient("mail1.vcu.edu")
'SmtpServer = "mail1.vcu.edu"
SMTPClient.Send(TheEmail)
MsgBox("Got " & CATCounter & " records back..." & vbCrLf & SubjectLine & vbCrLf & BodyText)
End If
Cnxn.Close()

End Sub
End Class

I'm receiving error message "Syntax error missing operator in query expression" any help you can provide is appreciated.


Private Sub btnEmailCat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEmailCat.Click
Dim SQLStmt, EmailAddress, SubjectLine, BodyText, CATDateString, DollarsAndCents, NoDecimal As String
Dim CATCounter As Integer
Dim GSIdNum, GSIdHash As Long
Dim Cnxn As New OleDbConnection( _
"Provider=Microsoft.JET.OLEDB.4.0;" _
& "Data Source=DB.mdb")
Cnxn.Open()
If Cnxn.State <> ConnectionState.Open Then
MsgBox("Unable to connect to the database...", MsgBoxStyle.Critical)
End
End If
SQLStmt = "SELECT Id, Descr, Price from GS WHERE Ledger = 4010"
Debug.Write("SQLStmt=" & SQLStmt)
Dim cmdSearch As New OleDbCommand(SQLStmt, Cnxn)
Dim CatEntries As OleDbDataReader = cmdSearch.ExecuteReader
If Not CatEntries.Read Then
MsgBox("No records were found with Ledger 4010")
Else
CATCounter = 0
GSIdHash = 0
CATDateString = Format(Now(), "yyyyMMddHHmmss")
EmailAddress = "ledgerengine@info465.net"
SubjectLine = "*!*!9999*" & CATDateString
BodyText = "CAT*9999*" & CATDateString & vbCrLf
Do
CATCounter += 1
DollarsAndCents = Format(CatEntries.Item("Price"), "0.00")
NoDecimal = Microsoft.VisualBasic.Left(DollarsAndCents, Len(DollarsAndCents) - 3) & _
Microsoft.VisualBasic.Right(DollarsAndCents, 2)
BodyText &= "ITEM*" & CatEntries.Item("Id") & "*" & CatEntries.Item("Descr") & _
"*" & NoDecimal & vbCrLf
GSIdNum = Val(CatEntries.Item("Id"))
GSIdHash += GSIdNum
Loop Until Not CatEntries.Read
BodyText &= "ECAT*" & CATCounter + 2 & "*" & GSIdHash
Dim TheEmail As New System.Net.Mail.MailMessage
TheEmail.To.Add("gs9191@info465.net")
TheEmail.From = New MailAddress("1spice@vcu.edu")
TheEmail.Subject = SubjectLine
MsgBox("Body Text =" & BodyText)
TheEmail.Body = BodyText
Dim SMTPClient As New SmtpClient("mail1.vcu.edu")
'SmtpServer = "mail1.vcu.edu"
SMTPClient.Send(TheEmail)
MsgBox("Got " & CATCounter & " records back..." & vbCrLf & SubjectLine & vbCrLf & BodyText)
End If
Cnxn.Close()

End Sub
End Class

how to connect a form in vb.net with the code

This article has been dead for over six months. Start a new discussion instead.