VBA Access SQL query issue - sql

I need your help please, I have a serious problem in my SQL request, it should show me the list of patients of the service Nephro but it shows me the list of all patients, so I think the SQL query does not work at all
This is the code :
Private Sub btnConnexion_Click()
Dim Categ As Integer
Dim Service As String
Dim IdProf As Integer
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String
Set db = CurrentDb
'vérification que l'utilisater a bien entrer e login et le mot de passe
Me.txtlogin.SetFocus
If IsNull(Me.txtlogin) Then
MsgBox "svp entrer votre login ", vbInformation, "login required "
Me.txtlogin.SetFocus
ElseIf IsNull(Me.txtmdp) Then
MsgBox "svp entrer votre mots de passe ", vbInformation, "mdp required "
Me.txtmdp.SetFocus
Else
'vérification que le login et le mdp sont corrects
If (IsNull(DLookup("login", "dbo_Authentification", "login='" & Me.txtlogin.Value & "'"))) Or _
(IsNull(DLookup("mdp", "dbo_Authentification", "mdp='" & Me.txtmdp.Value & "'"))) Then
MsgBox "login ou mdp incorrect"
Else
'récupération de l'IdCatégorie dans Categ, pour préciser les sessions des acteurs selon leurs catégories professionneles
Categ = DLookup("IdCategorie", "dbo_Professionnel", "IdProfessionnel = " & DLookup("IdCompte", "dbo_Authentification", "login='" & Me.txtlogin.Value & "'"))
'DoCmd.Close
If Categ = 3 Then
DoCmd.OpenForm "role"
Else
DoCmd.OpenForm "ListingPatients"
'Service récupère le service du professionnel authentifié pour l'afficher à l'entete du formulaire "ListingPatients"
Service = Nz(DLookup("IntituleServ", "dbo_Service", "IdService = " & DLookup("IdService", "dbo_Professionnel", "IdProfessionnel = " & DLookup("IdCompte", "dbo_Authentification", "login='" & Me.txtlogin.Value & "'"))), "inconnu")
Forms![ListingPatients]![txtIntituleServ] = Service
strSQL = "SELECT dbo_Patient.*, dbo_Service.IntituleServ, dbo_HospitalisatAcuelle.lit, dbo_Professionnel.IdProfessionnel, dbo_HospitalisatAcuelle.DateEntree, dbo_HospitalisatAcuelle.DateSortie FROM dbo_Service INNER JOIN ((dbo_Professionnel INNER JOIN dbo_Authentification ON dbo_Professionnel.IdProfessionnel = dbo_Authentification.IdCompte) INNER JOIN (dbo_Patient INNER JOIN (dbo_HospitalisatAcuelle INNER JOIN dbo_DonneePatientActuelles ON dbo_HospitalisatAcuelle.IdHosp = dbo_DonneePatientActuelles.IdHosp) ON dbo_Patient.IdPatient = dbo_DonneePatientActuelles.IdPatient) ON dbo_Professionnel.IdProfessionnel = dbo_HospitalisatAcuelle.IdProfessionnel) ON dbo_Service.IdService = dbo_Professionnel.Idservice WHERE (((dbo_HospitalisatAcuelle.DateEntree)<=Now()) AND ((dbo_HospitalisatAcuelle.DateSortie)>Now())) OR (((dbo_HospitalisatAcuelle.DateSortie) Is Null))"
strSQL = strSQL & " AND [dbo_Service]![IntituleServ] = ' " & Service & " ' "
Set rs = db.OpenRecordset(strSQL)
rs.Close
Set rs = Nothing
Set db = Nothing
End If
End If
End If
End Sub
Thank you very much

Check the WHERE clause of your VBA recordset SQL query. Your parenthesis set may be out of order. As you can see dbo_Service![IntituleServ] field is not contained but hangs out on an OR statement.
Consider moving the last parenthesis after the DateSortie >=Now() to after DateSortie Is Null.
WHERE
(
(
(dbo_HospitalisatAcuelle.DateEntree)<=Now()
) AND
(
(dbo_HospitalisatAcuelle.DateSortie)>Now()
)
)
OR
(
(
(dbo_HospitalisatAcuelle.DateSortie) Is Null
)
)
AND
[dbo_Service]![IntituleServ] = ' " & Service & " ' "

The DB object doesn't support queries, it can only be used to open entire tables.
Instead, use a QueryDef object. So the following code:
Set rs = db.OpenRecordset(strSQL)
should be
'up at the top
Dim qdf as QueryDef
'... code
Set qdf = db.CreateQueryDef("",strSQL)
set rs = qdf.OpenRecordSet(DbOpenSnapshot)
'... at the bottom
qdf.close
Also, there is a problem with your SQL the WHERE part should probably be
" WHERE (dbo_HospitalisatAcuelle.DateEntree<=Now() " & _
" AND (dbo_HospitalisatAcuelle.DateSortie>Now() OR dbo_HospitalisatAcuelle.DateSortie Is Null)) " & _
" AND [dbo_Service].[IntituleServ] = ' " & Service & " ' "
(note the placement of the brackets ())

Related

SQL query works in access but not in excel

I need to get data from a recordset. The SQL query works fine in MS Access and returns exactly the expected values, but when the same query is lunched in VBA Excel, I get the following error:
No value given for one or more required parameters
Do you have any ideas why this problem occurs?
Thank you.
Philippe-Olivier Roussel
Private Sub CBtype_AfterUpdate()
Dim strConnexion As String
Dim connexion As New ADODB.Connection
strConnexion = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source= " & Database & ""
connexion.Open strConnexion
Dim rsMarque As New ADODB.Recordset
Dim seltype As String
seltype = CBtype.Value
rsMarque.Open "SELECT DISTINCT tblMarque.marque_nom FROM tblMarque, tblModele WHERE " & _
" tblMarque.marque_id = tblModele.marque_id AND tblModele.marque_id IN " & _
" (SELECT DISTINCT tblModele.marque_id FROM tblModele, tblType " & _
" WHERE tblModele.type_id = tblType.type_id AND tblModele.type_id = " & _
" (SELECT tblType.type_id FROM tblType WHERE " & _
" (tblType.type_nom = " & seltype & ")))", connexion, adOpenStatic
rsMarque.MoveFirst
With UserForm2.CBmarque
.Clear
Do
.AddItem rsMarque!marque_nom
rsMarque.MoveNext
Loop Until rsMarque.EOF
End With
End Sub
This error message looks like an output from the DBMS rather than Excel
I think you might be missing the apostrophe before and after your string variable. See if
" (tblType.type_nom = '" & seltype & "')))" works (I'm assuming the column you're querying is varchar type, since you declared seltype as string)

SQL on VBA: Compilation error, a function or variable was expected

I have the code below but it isnt working. It gives me the error: Compilation error, a function or variable was expected.
I guess the error is on the Database.Execute method, but I didnt come with a solution yet.
Sub ChavesMontante()
Dim dbschaves As Database
Dim rschaves As DAO.Recordset
Dim tipodechave As String
Dim SQLCMD As String
Dim chave As String
Set dbschaves = CurrentDb
chave = "BED20777"
SQLCMD =
"(SELECT us.instalacao, ch.bloco, us.tipounidade " & _
"FROM (SELECT useccionadora, bloco " & _
"FROM sgdprd.redeprimaria rp " & _
"WHERE rp.useccionadora IS NOT NULL " & _
"CONNECT BY rp.nox = PRIOR rp.fontex AND rp.noy = PRIOR rp.fontey " & _
"START WITH rp.useccionadora = '" & chave & "' ) ch " & _
"INNER JOIN sgdprd.useccionadora us ON ch.useccionadora= us.instalacao) "
Debug.Print SQLCMD
Set rschaves = dbschaves.Execute(SQLCMD)
End Sub
Execute is used for action SQL statements (UPDATE, DELETE, INSERT), not to set a Recordset object.
Try the following changes:
Dim dbschaves As DAO.Database
...
Set rschaves = dbschaves.OpenRecordset(SQLCMD)
Also, remove the outer parens enclosing the entire SQL statement. I have never seen CONNECT BY PRIOR START WITH. Does the query open in Access?

Windows Mobile v 6.5 connecting to SQL Server 2008 R2

I have a problem connecting my windows mobile application developed using vb.net in my SQL server 2008 as my back end. Here is my connection string :
Data Source=STEPH-PC\SQL2008;Initial Catalog= MyDB; User ID = myusername; Password = mypassword;
It always give me an error that SQL server does not exist or access denied. Any help on how to solve this issue?
1- Testing connection Server versus Pocket PC:
First at all test if your SQL Server CE mobile agent connects to SQL Server CE Server agent. To do this you have to install SQL Server CE 3.5 in the server and in your Pocket PC. Search in google How to install SQL Server CE 3.5. In the process you create a Virtual Directory in Server and in that directory you got a file sqlcesa35.dll, so to test the connection in your Pocket PC browser write: http://ipserver/virtual_directory/sqlcesa35.dll (of course ipserver must be your server IP and virtual_directory must be your virtual directory name). Doing this you have to get in your Pocket PC the message:
Microsoft SQL Server Compact
Server Agent
At this point I have to mention that always you must have internet connection.
2- Retrieving files from the server (this is a sample code, not debugged, I only have taken some parts from other project and put them here).
Function get_companies(ByVal sSucursal As String, ByVal cn_Interface As System.Data.SqlServerCe.SqlCeConnection, _
ByVal cmd_Interface As System.Data.SqlServerCe.SqlCeCommand, ByVal dr_Interface As System.Data.SqlServerCe.SqlCeDataReader) As Boolean
get_companies = False
Dim _strRemoteConnect As String
Dim _strLocalConnect As String
Dim _strInternetURL As String = sInternetURL
'The last variable sInternetURL is something like: http://ip_server/virtual_directory/sqlcesa35.dll
_strRemoteConnect = "Provider=SQLOLEDB;Data Source=" & sIPSQLServer & ";Initial Catalog=" & sBDSQLServer & ";User Id=" & sUserSQLServer & ";Password=" & sClaveSQLServer
'sIPSQLServer is the server ip where is running SQL Server
'sBDSQLServer is your DataBase server.
_strLocalConnect = "Data Source=" & sPath & "\" & sDataBase_Interface & "; Password=" & sPassword
'sPath is your directory in your Pocket PC, begings with \
'sDataBase_Interface is the database in my Pocket PC, an .sdf file
Dim rda As System.Data.SqlServerCe.SqlCeRemoteDataAccess = New System.Data.SqlServerCe.SqlCeRemoteDataAccess
rda.InternetLogin = sUserInternet 'a valid user in your domain
rda.InternetPassword = sClaveInternet
rda.InternetUrl = _strInternetURL
rda.LocalConnectionString = _strLocalConnect
Do While True
Try
'In server database there is a table: Monedas
rda.Pull("_Monedas", "Select Moneda, Descripcion, Abreviada From Monedas Where Sucursal = '" & sSucursal & "'", _
_strRemoteConnect, System.Data.SqlServerCe.RdaTrackOption.TrackingOff)
Exit Do
Catch exc As System.Data.SqlServerCe.SqlCeException
ShowErrorSqlServerCE(exc)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Loop
'read the data received, just testing, may be this code not to be here because you process the data outside the function.
Try
cmd_Interface.CommandText = "Select Moneda, Descripcion, Abreviada From _Monedas"
dr_Interface = cmd_Interface.ExecuteReader()
Do While dr_Interface.Read()
messagebox.show("Moneda = " & dr_interface("Moneda") & " - " & dr_interface("Descripcion") & " - " & dr_interface("Abreviada"), _
"Currencies Received", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
Loop
get_companies = true
Catch exc As System.Data.SqlServerCe.SqlCeException
ShowErrorSqlServerCE(exc)
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1)
Finally
'If cn_Interface.State <> ConnectionState.Closed Then
' cmd_Interface.Dispose()
' cn_Interface.Close()
' cn_Interface.Dispose()
'End If
End Try
End Function
3- Excecuting a sentence in Database Server from your Pocket PC and Transferring data from Pocket to Server:
Function EnviarClientesNuevos(ByVal sSucursal As String, ByVal sZona As String, ByVal sRuta As String) As Boolean
Dim sLineas As String
Dim nRegs As Integer
Dim cn_Interface As System.Data.SqlServerCe.SqlCeConnection
Dim cmd_Interface As System.Data.SqlServerCe.SqlCeCommand
EnviarClientesNuevos = False
Dim _strRemoteConnect As String
Dim _strLocalConnect As String
Dim _strInternetURL As String = sInternetURL
_strRemoteConnect = "Provider=SQLOLEDB;Data Source=" & sIPSQLServer & ";Initial Catalog=" & sBDSQLServer & ";User Id=" & sUserSQLServer & ";Password=" & sClaveSQLServer
_strLocalConnect = "Data Source=" & sPath & "\" & sDataBase_Interface & "; Password=" & sPassword
Dim rda As System.Data.SqlServerCe.SqlCeRemoteDataAccess = New System.Data.SqlServerCe.SqlCeRemoteDataAccess
rda.InternetLogin = sUserInternet
rda.InternetPassword = sClaveInternet
rda.InternetUrl = _strInternetURL
rda.LocalConnectionString = _strLocalConnect
Do While True
If DropTableE("_NEW_CLIENTES_XX") Then
Try
'_NEW_CLIENTES_XX is a table in your SQL Server (The server, not the Pocket)
rda.Pull("_NEW_CLIENTES_XX", "Select Id, Sucursal, Zona, CodCli, Nombre, Direccion, Ruc, Clase, Ruta " & _
"FROM _NEW_CLIENTES_XX WHERE Sucursal = ''", _strRemoteConnect, SqlServerCe.RdaTrackOption.TrackingOn)
'In where clause I compare to '' because I only need the structure
Exit Do
Catch exc As System.Data.SqlServerCe.SqlCeException
ShowErrorSqlServerCE(exc)
Exit Function
Catch ex As Exception
MessageBox.Show(ex.Message)
Exit Function
End Try
End If
Loop
Try
'--
cn_Interface = New System.Data.SqlServerCe.SqlCeConnection
cn_Interface.ConnectionString = "Data Source=" & sPath & "\" & sDataBase_Interface & ";Password=" & sPassword
cn_Interface.Open()
cmd_Interface = cn_Interface.CreateCommand()
cmd_Interface.CommandType = CommandType.Text
'--
'here I have an open connection to another database in my Mobile Device. Here I have to mention that I work with 2 databases in my mobile device:
'One database for getting the data from server, I only use it when I get data from server and when I send data to server
'and other database which is my main database, the database that is used all the day storing customers transactions.
'here I already have open (outside this function) the connection to this second database, but the sentence are the same above,
'something like this:
'Try
' cn = New System.Data.SqlServerCe.SqlCeConnection
' cn.ConnectionString = "Data Source=" & sPath & "\" & sDataBase_Ppal & ";Password=" & sPassword
' cn.Open()
' cmd = cn.CreateCommand()
' cmd.CommandType = CommandType.Text
'Read the data from my main Pocket PC database
cmd.CommandText = "SELECT CodCli, Nombre, Direccion, Ruc, Clase From CLIENTES WHERE CLASE IN ('N', 'M')"
dr = cmd.ExecuteReader()
Do While dr.Read()
'Insert the data in the table structure that I get above.
'remember that this table is in the database that only is used when transferring data, its a temporal database.
cmd_Interface.CommandText = "INSERT INTO _NEW_CLIENTES_XX (Sucursal, Zona, CodCli, Nombre, Direccion, Ruc, Clase, Ruta) " & _
"VALUES('" & sSucursal & "', '" & sZona & "', " & dr("CodCli") & ", '" & _
dr("Nombre") & "', '" & dr("Direccion") & "', '" & dr("Ruc") & "', '" & _
dr("Clase") & "', '" & sRuta & "')"
nRegs = cmd_Interface.ExecuteNonQuery()
Loop
dr.Close() : dr.Dispose()
Catch exc As System.Data.SqlServerCe.SqlCeException
ShowErrorSqlServerCE(exc)
Exit Function
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1)
Exit Function
Finally
Try
dr.Close()
dr.Dispose()
Catch ex As Exception
End Try
'If cn.State <> ConnectionState.Closed Then
' cmd.Dispose()
' cn.Close()
' cn.Dispose()
'End If
If cn_Interface.State <> ConnectionState.Closed Then
cmd_Interface.Dispose()
cn_Interface.Close()
cn_Interface.Dispose()
End If
End Try
Do While True
Try
'I excecute a sentence in the Server. I delete the data in _NEW_CLIENTES_XX which is a work table in SQL server.
rda.SubmitSql("Delete From _NEW_CLIENTES_XX Where Sucursal = '" & sSucursal & "' AND Zona = '" & sZona & "' And Ruta = '" & sRuta & "'", _strRemoteConnect)
'I send the data to server
rda.Push("_NEW_CLIENTES_XX", _strRemoteConnect, System.Data.SqlServerCe.RdaBatchOption.BatchingOn)
EnviarClientesNuevos = True
Exit Do
Catch exc As System.Data.SqlServerCe.SqlCeException
ShowErrorSqlServerCE(exc)
Exit Function
Catch ex As Exception
MessageBox.Show(ex.Message)
Exit Function
End Try
Loop
End Function
Generalities:
Function DropTableP(ByVal sTabla As String) As Boolean
'Dim cn_Interface As System.Data.SqlServerCe.SqlCeConnection
'Dim cmd_Interface As System.Data.SqlServerCe.SqlCeCommand
'Dim dr_Interface As System.Data.SqlServerCe.SqlCeDataReader
Dim nRegs As Integer
Try
'cn_Interface = New System.Data.SqlServerCe.SqlCeConnection("Data Source=" & sPath & "\" & sDataBase_Ppal & "; Password=" & sPassword)
'cn_Interface.Open()
'cmd_Interface = cn_Interface.CreateCommand()
'cmd_Interface.CommandType = CommandType.Text
cmd.CommandText = "Select TABLE_NAME From INFORMATION_SCHEMA.TABLES Where TABLE_NAME = '" & sTabla & "'"
dr = cmd.ExecuteReader()
If dr.Read() Then
dr.Close()
dr.Dispose()
cmd.CommandText = "DROP TABLE " & sTabla
nRegs = cmd.ExecuteNonQuery()
DropTableP = True
Else
dr.Close()
dr.Dispose()
DropTableP = True
End If
Catch exc As System.Data.SqlServerCe.SqlCeException
ShowErrorSqlServerCE(exc)
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
'If cn_Interface.State <> ConnectionState.Closed Then
' cn_Interface.Close()
' cn_Interface.Dispose()
'End If
End Try
End Function
Sub ShowErrorSqlServerCE(ByVal exc As System.Data.SqlServerCe.SqlCeException)
Dim bld As New System.Text.StringBuilder
Dim err As System.Data.SqlServerCe.SqlCeError
Dim errorCollection As System.Data.SqlServerCe.SqlCeErrorCollection = exc.Errors
Dim errPar As String
Dim numPar As Integer
' Loop through all of the errors.
For Each err In errorCollection
bld.Append(ControlChars.Cr & " Error Code: " & err.HResult.ToString("X"))
bld.Append(ControlChars.Cr & " Message : " & err.Message)
bld.Append(ControlChars.Cr & " Minor Err.: " & err.NativeError)
bld.Append(ControlChars.Cr & " Source : " & err.Source)
' Loop through all of the numeric parameters for this specific error.
For Each numPar In err.NumericErrorParameters
If numPar <> 0 Then
bld.Append(ControlChars.Cr & " Num. Par. : " & numPar.ToString())
End If
Next numPar
' Loop through all of the error parameters for this specific error.
For Each errPar In err.ErrorParameters
If errPar <> [String].Empty Then
bld.Append(ControlChars.Cr & " Err. Par. : " & errPar)
End If
Next errPar
' Finally, display this error.
MessageBox.Show(bld.ToString(), "SQL Server CE")
' Empty the string so that it can be used again.
bld.Remove(0, bld.Length)
Next err
End Sub
As I said above: the code that I put here needs to be debugged...I have only extracted some parts from my project and put here. Hope this will help you!

String truncated at 255 chars when got from a MS Access SQL query

I'm having problems with a String var in which I put a SQL query I've saved in MS Access. It works like this:
I generate a list through a SELECT query
Using a menu at a Userform with Excel VBA, I choose columns to order the list
As I will have to order many lists in many ways, I decided to create a Sub ordenar(ByVal sqlLista As String, ByVal sqlOrd As String).
sqlLista contains the name of the SELECT query that generates the list I want to order; sqlOrd contains the ORDER BY <col1>... piece of query:
sqlLista = "ListaAbonos"
ListaAbonos (Access query) =
SELECT Left('0000',4-Len(c.nro_cliente)) & c.nro_cliente & ' - ' & IIF(IsNull(razon_social),apellido & ' ' & nombre, razon_social), a.cod_localidad & '/' & cod_cobrador, cod_abono, descripcion, tel_verificacion, fecha_alta, a.direccion, s.nombre_servicio, ts.valor, a.estado
FROM ((abonos AS a
INNER JOIN servicios AS s ON a.cod_servicio = s.cod_servicio)
INNER JOIN tarifas_servicio AS ts ON a.cod_servicio = ts.cod_servicio)
INNER JOIN clientes AS c ON a.nro_cliente = c.nro_cliente;
sqlOrd = "ORDER BY..."
[NOTE: I ran the entire query (SELECT...ORDER BY...) and IT WORKS PROPERLY]
DECLARATIONS
Public Sub ordenar(ByVal sqlLista As Variant, ByVal sqlOrd As Variant)
Dim cs As String
Dim sPath As String
Dim sql As String
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim qd As DAO.QueryDef
CONNECTION TO DB:
sPath = "C:\Users\Ezequiel\Documents\ZEN.accdb"
cs = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & sPath & ";Persist Security Info=False;"
Set cn = New ADODB.Connection
cn.Open cs
Set rs = New ADODB.Recordset
With rs
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = adLockOptimistic
End With
THIS IS THE IMPORTANT PART OF THE CODE:
Set qd = CurrentDb.QueryDefs(sqlLista)
sql = Left(qd.sql, Len(qd.sql) - 1) & " " & sqlOrd
Set rs = cn.Execute(sql)
When I execute the Sub, I get an error
Characters found after end of sql statement
Inspecting "sql" and "qd.sql" I found that the query had been truncated:
sql = qd.sql = "SELECT Left('0000',4-Len(c.nro_cliente)) & c.nro_cliente & ' - ' & IIF(IsNull(razon_social),apellido & ' ' & nombre, razon_social), a.cod_localidad & '/' & cod_cobrador, cod_abono, descripcion, tel_verificacion, fecha_alta, a.direccion, s.nombre_serv
Note that the ORDER BY doesn't even appear as it's beyond the first 255 chars.
What's the problem? Thanks!

SQL Error Access 2010 VBA Update Command

I need help figuring out an error in my SQL statement. I have been trying several things, but nothing seems to work?
This is the error message I receive
Run-time error '3075':
Syntax error (missing operator) in query expression '([description] = Manufacturing and Delivery Schedule AND [pr_num] = 83)'.
This is my code:
Private Sub Command6_Click()
' ===================================================
' Receives the selected item in the combo box
' ===================================================
' Open the Database connection
Dim data_base As Database
Set data_base = CurrentDb
' Grab description and pr number from the form
Dim desc As string
dim pr_number as long
desc = Combo4.Value
pr_number = Text8.Value
' Build the query
Dim query As String
query = "UPDATE VDR_Table " & _
"SET [received] = [p1] " & _
"WHERE ([description] = " & desc & _
" AND [pr_num] = " & pr_number & ");"
Dim rec_set As DAO.Recordset
Set rec_set = data_base.OpenRecordset(query)
' Build the QueryDef
Set qd = data_base.CreateQueryDef("")
qd.SQL = query
' Execute query
qd.Parameters("p1").Value = true
qd.Execute
' Close nad null record set
rec_set.close
set rec_set = nothing
' Close the connection to the database
data_base.Close
' Prompt the user success
MsgBox "Item has been received"
End Sub
Thanks in advance for any help!
You need to enclose the description field value you are setting in quotes since it is a string field. It should look like this:
' Build the query
Dim query As String
query = "UPDATE VDR_Table " & _
"SET [received] = [p1] " & _
"WHERE ([description] = '" & desc & _
"' AND [pr_num] = " & pr_number & ");"
Removed the links below since they don't matter in this case.
Also, I would recommend using parameters instead of string concatenations to avoid SQL injections. Here's an example of using parameters with VBA - http://support.microsoft.com/kb/181734 - and here is some reasoning on why to use parameterized sql - http://www.codinghorror.com/blog/2005/04/give-me-parameterized-sql-or-give-me-death.html.