I have the following script to add signature in Outlook:
...
Set objShape = objSelection.InlineShapes.AddPicture("\\blabla\blabla\blabla\blabla\blabla\" & strlogin2 & ".jpg")
url = "http://url.com.mx/assets/aviso.pdf"
objSelection.Font.Italic = True
objSelection.Font.Size = 09
objSelection.TypeText "El Aviso de Privacidad de XXXXXX, está disponible en "
Set objLink = objSelection.Hyperlinks.Add(objSelection.Range, url)
objSelection.TypeText ", es aplicable a todos los Titulares de Datos Personales obtenidos por la Empresa, a través de cualquier medio físico o electrónico y para los fines que se hace referencia en el mismo."
objSelection.Font.Color = RGB(255, 102, 0)
objLink.Range.Font.Name = "Calibri"
objLink.Range.Font.Size = 09
objLink.Range.Font.Bold = True
objSelection.Font.Bold = True
objSelection.Font.Color = RGB(105, 105, 105)
objSelection.Font.Color = RGB(105, 105, 105)
objSelection.TypeParagraph()
Set objSelection = objDoc.Range()
objSignatureEntries.Add "Firma Corporativa XXXX", objSelection
objSignatureObject.NewMessageSignature = "Firma Corporativa XXXXXX"
objSignatureObject.ReplyMessageSignature = "Firma Corporativa XXXXX"
objDoc.Saved = True
objWord.Quit
This is the result:
I need set a line break between the image and text.
Type a paragraph after you inserted the image:
Set objShape = objSelection.InlineShapes.AddPicture(...)
objSelection.TypeParagraph
Related
Closed. This question is not written in English. It is not currently accepting answers.
Stack Overflow is an English-only site. The author must be able to communicate in English to understand and engage with any comments and/or answers their question receives. Don't translate this post for the author; machine translations can be inaccurate, and even human translations can alter the intended meaning of the post.
Closed 5 days ago.
Improve this question
Al usar la funcion LoadPicture(ruta + nombre imagen) para cargar una imagen en un control de imagen dentro de un formulario, muestra un error que dice: la función LoadPicture no está definida.
Intento cargar una imagen jpg pero tan pronto inicia el sub genera el error, estoy trabajando con VMware Fusion desde una mac.
posteriormente la idea es guardar la imagen en una hoja Excel cuando el usuario haga click en el botón guardar.
Este es mi sub:
Private Sub Buscar_imagen_Click()
Dim ruta As String
Dim Nom_image As String
If trim$(NombreProducto) <> "" And trim$(NombreReferencia.Value) <> "" Then
Nom_image = "'" & trim$(NombreProducto) & "_" & trim(NombreReferencia.Value) & "'"
RutaImagen = ActiveWorkbook.Path & Application.PathSeparator & "Imagenes_Producto" & Application.PathSeparator & Nom_image & ".Jpg"
ControlProductos.Image_fotomochila = LoadPicture(ruta)
Else
MsgBox ("Para el nombre del producto ingreso no existe imagen")
End If
End Sub
I trying to run this code:
Dim jsonString, jsonDictionary
jsonString = "{ ""name"": ""John"", ""age"": 30, ""city"": ""New York"" }"
Set jsonDictionary = JSONToDictionary(jsonString)
MsgBox(jsonDictionary.Item("name")) ' -> "John"
MsgBox(jsonDictionary.Item("age")) ' -> 30
MsgBox(jsonDictionary.Item("city")) ' -> "New York"
Function JSONToDictionary(jsonString)
' Crea un objeto de script
Set jsonObject = CreateObject("ScriptControl")
' Establece la sintaxis JSON como el lenguaje de script
jsonObject.Language = "JScript"
' Utiliza el método eval() del objeto de script para parsear la cadena JSON
Set jsonDictionary = eval("(" + jsonString + ")")
' Devuelve el objeto diccionario
JSONToDictionary = jsonDictionary
End Function
But I get the error: "The ActiveX component can't create the object: 'ScriptControl' ".
Also I get the error: "System: This operation is not supported with BTT enabled".
I've tried everything but it doesn't work, would you know how to fix it?
I have a stored procedure in oracle getspname which I will receive 2 input parameters (varchar2 and number) and one output param of cursor type.
The application that is executing this stored procedure is a bit old, it is using VB6 in IIS6 to connect to this SP in ORACLE and I am migrating it to IIS7.
Provider=MSDAORA.1;Data Source=XXXXXXXX;User ID=XXXXXXXXX;Password=XXXXXX
and SQL is:
{call schema.Pkg_name.getspname(?,?,{resultset 0, io_cursor})}
Params: 11111111;0
IN IIS6 has no problem executing the procedure and returning the cursor data,
in IIS7 if not, it sent input parameters, this also works, but I need to send it these fields to comply with the applied business logic.
This solution was also implemented but the error is replicated in SP that has only input or output parameters of type varchar2 stackoverflow.com/a/50643323/5904375
VB6:
Public Function execProcedure( _
ByVal sConnString As String, _
ByVal sSQL As String, _
ByRef oRs As Variant, _
ByVal sParameters As Variant, _
ByRef vntRespuesta As Variant, _
Optional Encrypt As Boolean _
) As Integer
Dim Params, i
Dim RsCmd
Dim oRecordSet
Dim RspMsg As Variant
Dim RspMsg1 As Variant
Dim RspMsg2 As Variant
Dim oConec
Dim BeforeConn As Boolean
Dim auxErr As Integer
Dim auxValue As Variant
Dim StringReg As Variant
Dim oEncrypt
Dim bEncrypt As Boolean
On Error GoTo Error_handler
'** Se verifica encriptacion del string de conexion
bEncrypt = False
If Not IsMissing(Encrypt) Then
If Encrypt Then bEncrypt = True
End If
If bEncrypt Then
Set oEncrypt = CreateObject("NR_DBconn.Encrypt")
StringReg = oEncrypt.EncriptarChrTran("azv", sConnString, 2)
Set oEncrypt = Nothing
Else
StringReg = sConnString
End If
BeforeConn = True
Set ctxObject = GetObjectContext
strNombreObjeto = "ADODB.Command"
Set RsCmd = ctxObject.CreateInstance("ADODB.Command")
'Set RsCmd = CreateObject("ADODB.Command")
strNombreObjeto = "ADODB.Recordset"
Set oRecordSet = ctxObject.CreateInstance("ADODB.Recordset")
'Set oRecordSet = CreateObject("ADODB.Recordset")
strNombreObjeto = "ADODB.Connection"
Set oConec = ctxObject.CreateInstance("ADODB.Connection")
'Set oConec = CreateObject("ADODB.Connection")
'*
'* Verifica si el sSQL es válido
'*
If sSQL = "" Or Len(sSQL) = 0 Then
ctxObject.SetAbort
'La transaccion finaliza con error
Err.Raise INSTRUCCION_INVALID, "Verificar sSQL"
End If
'*
'* Se verifica string de conexión
'*
If (StringReg = "") Then
ctxObject.SetAbort
'La transaccion finaliza con error
Err.Raise INSTRUCCION_INVALID, "Verificar string de Conexion"
End If
BeforeConn = False
oConec.Open StringReg
With RsCmd
.ActiveConnection = oConec
.CommandText = sSQL
.CommandType = adCmdText ' adCmdStoredProc 'adCmdText
If Len(sParameters) <> 0 Then
Params = Split(sParameters, ";")
For i = 0 To UBound(Params)
.Parameters(i).Direction = adParamInput
.Parameters(i).Value = Params(i)
Next i
End If
End With
oRecordSet.CursorLocation = adUseClient
oRecordSet.CursorType = adOpenStatic
oRecordSet.LockType = eltBatchOptimistic
Set oRecordSet = RsCmd.Execute()
'*
'* Verifica el resultado
'*
auxErr = -1
If oRecordSet.State = 1 Then
If oRecordSet.EOF Or oRecordSet.BOF Or oRecordSet Is Nothing Then
RspMsg1 = "0"
RspMsg2 = "No se obtuvo recordset de vntRespuesta - warning"
RspMsg = "[" & RspMsg1 & "]: " & RspMsg2
auxErr = 0
Set oRs = Nothing
Else
RspMsg1 = "0"
RspMsg2 = ""
RspMsg = "" '"[" & RspMsg1 & "]: " & RspMsg2
'------traspasa el recordsetresult a recordset desconectado
Dim Rsx
Dim j
Dim NumFields
Set Rsx = New ADODB.Recordset
NumFields = oRecordSet.Fields.Count - 1
With Rsx
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = eltBatchOptimistic
Set .ActiveConnection = Nothing
For i = 0 To NumFields
With .Fields
.Append oRecordSet.Fields(i).Name, adBSTR
End With
Next i
.Open
Do While Not oRecordSet.EOF
.AddNew
For j = 0 To NumFields
auxValue = oRecordSet.Fields(j)
.Fields(j) = CheckNull(auxValue)
Next j
oRecordSet.MoveNext
Loop
.MoveFirst
End With
'-------------
Set oRs = Rsx
'Set oRecordSet.ActiveConnection = Nothing
Set oRecordSet = Nothing
Set Rsx = Nothing
auxErr = 1
End If
Else
RspMsg1 = "2"
RspMsg2 = "No se obtuvo recordset de vntRespuesta - operacion no necesita"
RspMsg = "[" & RspMsg1 & "]: " & RspMsg2
auxErr = 2
Set oRs = Nothing
End If
vntRespuesta = RspMsg
Set RsCmd = Nothing
oConec.Close
Set oConec = Nothing
' If IsObject(oRs) Then
' execProcedure = oRs.RecordCount
' Else
execProcedure = auxErr
' End If
'*
'* La transacción finaliza exitosamente
ctxObject.SetComplete
Exit Function
Error_handler:
execProcedure = -1
RspMsg = ErrorMessage("SQLserver.execProcedure.", Err.Number, Err.Source, Err.Description, sSQL)
'*
'* Fin de la función, ha ocurrido un Error Fatal
'*
On Error Resume Next
If Not BeforeConn Then
If (oConec.State = adStateOpen) Then
oConec.Close
End If
End If
Set oConec = Nothing
vntRespuesta = RspMsg
'*
'* La transacción finaliza con error
'*
ctxObject.SetAbort
End Function
Function Error VB6:
Private Function ErrorMessage(ErrPath, ErrCod, ErrSource, ErrDescription, sSQL)
Dim RspMsg1
Dim RspMsg2
Dim strPathError
strPathError = "[" & ErrPath & "." & Err.Source & "] "
Select Case (ErrCod)
Case INSTRUCCION_INVALID
RspMsg1 = INSTRUCCION_INVALID
RspMsg2 = strPathError & " El string 'sSQL' esta mal formado." & _
"Verifique que el String 'sSQL' esté de acuerdo al formato SQL"
Case STRING_CONNECTION
RspMsg1 = STRING_CONNECTION
RspMsg2 = strPathError & "No existe string de conexion para esta Aplicacion "
Case NOT_REC_RETURN
RspMsg1 = NOT_REC_RETURN
RspMsg2 = strPathError & "No se retornaron registros." & _
"Intente de nuevo o con otros valores en el 'sSQL'. Este error puede deberse a una falla en la conexion con la Base de Datos. (" & sSQL & ")"
Case NOT_REC_FOUND
RspMsg1 = NOT_REC_FOUND
RspMsg2 = strPathError & "No se encontro registros." & _
"Intente con otros valores en la 'sSQL'. (" & sSQL & ")"
Case 429:
RspMsg1 = "-1"
RspMsg2 = strPathError & " No se puede crear el componente: '" & strNombreObjeto & _
"Verifique que el componente esté instalado correctamente."
'Error manipulado. En parametros de la base de datos.
Case -2147217887
RspMsg1 = "-1"
RspMsg2 = strPathError & "Error al insertar campo." & _
"Verifique el largo del valor del campo no exceda al maximo permitido en la definicion de la TABLA de la Base de Datos."
Case Else 'Cualquier otro tipo de Error
RspMsg1 = "-1"
RspMsg2 = strPathError & ErrDescription
End Select
ErrorMessage = "[" & RspMsg1 & "]: " & RspMsg2
End Function
This SP was also independently tested to rule out any problem, it works correctly
SP ORACLE:
PROCEDURE getspname (value IN varchar2 ,value2 IN number , io_cursor IN OUT t_cursor)
AS
BEGIN
........
END;
END getspname;
I solved this on Friday 08/17/2020 at 3 AM,
I decided to make a call directly to the oracle SP from the ASP using provider (OraOLEDB.Oracle) and thus replicate the behavior, this was giving an error of "Run-time error 3001 Arguments Are Of The Wrong Type… when setting ADODB.Command object members"
The ASP code:
Name file: test.asp
<%# Language=VBScript %>
<%Response.Buffer = false%>
<%Response.Expires = 0%>
<%
Dim strConnect
strConnect = "Provider=OraOLEDB.Oracle;Data Source=XXXXXXXX;User ID=XXXXXXXXX;Password=XXXXXX"
Dim cn, rs, cmd, param
set cn = Server.CreateObject( "ADODB.Connection" )
cn.Open Cstr(strConnect)
set cmd = server.CreateObject ("ADODB.Command")
with cmd
set .ActiveConnection = cn
.NamedParameters = True
.CommandText = "{call schema.Pkg_name.getspname({resultset 0, io_cursor})}"
.CommandType = 1
end with
set rs = server.CreateObject ( "ADODB.Recordset" )
set rs = cmd.execute
Set rs = cmd.Execute
Do Until rs.EOF
for each x in rs.fields
response.write(x.name)
response.write("=")
response.write(x.value)
response.write(", ")
next
response.write("<br />")
rs.MoveNext
Loop
rs.Close
%>
<%
Dim strConnect_cn
strConnect_cn = "Provider=OraOLEDB.Oracle;Data Source=XXXXXXXX;User ID=XXXXXXXXX;Password=XXXXXX"
Dim cn_cn, rs_cn, cmd_cn , param1, param2
set cn_cn = Server.CreateObject( "ADODB.Connection" )
cn_cn.Open Cstr(strConnect_cn)
set cmd_cn = server.CreateObject ("ADODB.Command")
with cmd_cn
set .ActiveConnection = cn_cn
.CommandText = "{call schema.Pkg_name.getspname(?,?,{resultset 0, io_cursor})}"
.CommandType = 1
end with
cmd_cn.parameters.append(cmd_cn.createParameter("", adVariant, adParamInput, , "11111111"))
cmd_cn.parameters.append(cmd_cn.createParameter("", adVariant, adParamInput, , "0"))
set rs_cn = server.CreateObject ( "ADODB.Recordset" )
set rs_cn = cmd_cn.execute
Set rs_cn = cmd_cn.Execute
Do Until rs_cn.EOF
for each x in rs_cn.fields
response.write(x.name)
response.write("=")
response.write(x.value)
response.write(", ")
next
response.write("<br />")
rs_cn.MoveNext
Loop
rs_cn.Close
%>
<html>
<head>
<title> Links </title>
</head>
<body>
<p>test.asp</p>
</body>
</html>
This code throws me the following problem with input parameters, where the arguments were of the wrong type.
"Run-time error 3001 ‘Arguments Are Of The Wrong Type, Are Out Of The
Acceptable Range, or are in conflict with one another’ upon invocation
of"
And according to the documentation that I found this is fine
http://www-db.deis.unibo.it/courses/TW/DOCS/w3schools/asp/met_comm_createparameter.asp.html
https://welookups.com/asp/ado_datatypes.html
https://learn.microsoft.com/en-us/sql/ado/reference/ado-api/datatypeenum?view=sql-server-ver15
After much searching in forums on the Internet I found that the following article:
http://keencod.in/?p=23
This explains:
...that error is fired because of late binding of library references,
so VB simply did not know of adCmdStoredProc and other constants. That
meant that this error has nothing to do with ADODB or Ole or SP...
Therefore, you only had to declare these values at the beginning as constants, just as explained in the article.
So at the beginning of my ASP (test.asp) code add:
Const adVarChar = 200
Const adParamInput = &H1
Const adParamOutput = &H2
Const adCmdStoredProc = &H4
Const adVariant = 12
And magic, it worked!!
Then I modified my VB6 code, which was the one I had to use to comply with the business logic of the applications that were being migrated.
At the beginning of the file add:
Const adVarChar As Long = 200
Const adParamInput As Long = &H1
Const adParamOutput As Long = &H2
Const adCmdStoredProc As Long = &H4
Const adCmdText As Long = 1
Const adUseClient As Long = 3
Const adOpenStatic As Long = 3
Const adVariant As Long = 12
And then change my VB6 code like this:
With RsCmd
.ActiveConnection = oConec
.CommandText = sSQL
.CommandType = adCmdText ' adCmdStoredProc 'adCmdText
If Len(sParameters) <> 0 Then
.NamedParameters = True
Params = Split(sParameters, ";")
For i = 0 To UBound(Params)
.Parameters.Append (.CreateParameter("", adVariant, adParamInput, , Params(i)))
Next i
End If
End With
Using provider: MSDAORA.1
And with this the problem was solved!!
This is my story, thank you very much!!
End.
Thanks for the web site and thanks for taking you time to read this.
I created a signature based on a VBS Script i pulled for numerous web sites online and got the signature almost like i would like it to be, just got a few more tweaks before i stop messing with it. i can´t seem to get the vertical alignment to work. Can you help me out please.
The code is below and the image showing refering to what i need is attached.
i need to move the right side image to the a bottom aligned position
i need to remove the space i have between the blue bar and the table above.
Appriciate the help, i am not a programmer just trying to do my best to automate signatures in outlook.
On Error Resume Next
'Option Explicit
Dim objSysInfo,strUser,objUser,strName,strMail,strWebAddr,strCompany,strDepartment,strStreetAddr,strHomePhone,strIpPhone,strMobile
Dim objWord,objDoc,objSelection,objEmailOptions,objSignatureObject,objSignatureEntries,objLink,strlogoATL,strlogoMA,strlogoBAR
Dim objRange,objTable
Set objSysInfo = CreateObject("ADSystemInfo")
strUser = objSysInfo.UserName
Set objUser = GetObject("LDAP://" & strUser)
strName = objUser.FirstName &" "& objUser.LastName
strMail = objuser.mail
strWebAddr = objuser.wWWHomePage
strCompany = objuser.Company
strDepartment = objUser.Department
strStreetAddr = objuser.streetaddress
strHomePhone = objuser.HomePhone
strIpPhone = objuser.ipPhone
strMobile = objuser.Mobile
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Add()
Set objSelection = objWord.Selection
objSelection.Style = "No Spacing"
Set objEmailOptions = objWord.EmailOptions
Set objSignatureObject = objEmailOptions.EmailSignature
Set objSignatureEntries = objSignatureObject.EmailSignatureEntries
'Name of Staff
objSelection.Font.Name = "Verdana"
objSelection.Font.Size = "10"
objSelection.Font.Color = RGB(91,91,91)
objSelection.TypeText strName
objSelection.TypeText(Chr(11))
objSelection.TypeParagraph()
'Mail
objSelection.Font.Name = "Verdana"
objSelection.Font.Size = "8"
objSelection.Font.Color = RGB(91,91,91)
Set objLink = objSelection.Hyperlinks.Add(objSelection.Range, "mailto: " & strMail, , , strMail)
objSelection.TypeText(Chr(11))
'Tel
objSelection.Font.Name = "Verdana"
objSelection.Font.Size = "8"
objSelection.Font.Color = RGB(91,91,91)
objSelection.TypeText "Ext : "& strIpPhone & " " & " "& chr(124) & " Telem" & Chr(243) & "vel : " & strMobile
objSelection.TypeText(Chr(11))
objSelection.TypeParagraph()
'Department
objSelection.Font.Name = "Verdana"
objSelection.Font.Size = "8"
objSelection.Font.Color = RGB(0,153,181)
objSelection.TypeText strDepartment
objSelection.TypeText(Chr(11))
'Address
objSelection.Font.Name = "Verdana"
objSelection.Font.Size = "8"
objSelection.Font.Color = RGB(0,153,181)
objSelection.TypeText strStreetAddr
objSelection.TypeText(Chr(11))
objSelection.TypeParagraph()
'Company Contact details
objSelection.Font.Name = "Verdana"
objSelection.Font.Color = RGB(0,153,181)
objSelection.TypeText "Tel : "& strHomePhone & " " & chr(124) & " "
'Web
objSelection.Font.Name = "Verdana"
objSelection.Font.Color = RGB(0,153,181)
set objLink = objSelection.Hyperlinks.Add(objSelection.Range,strWebAddr)
strlogoATL="c:\Utils\Assinatura\ins_atl.jpg"
strlogoMA="c:\Utils\Assinatura\ins_ma.jpg"
strlogoBAR="c:\Utils\Assinatura\ins_bar.jpg"
Set objRange = objSelection.Range
objDoc.Tables.Add objRange, 1, 2
Set objTable = objDoc.Tables(1)
objTable.leftpadding = 0
objTable.rightpadding = 0
objTable.Columns(1).Width = objWord.CentimetersToPoints(12.00)
objTable.Cell(1, 1).Range.InlineShapes.AddPicture(strlogoATL)
objTable.Columns(2).Width = objWord.CentimetersToPoints(12.00)
objTable.Cell(1, 2).Range.ParagraphFormat.Alignment = 2
objTable.Cell(1, 2).Range.VerticalAlignment = wdAlignVerticalCenter
objTable.Cell(1, 2).Range.InlineShapes.AddPicture(strlogoMA)
objSelection.EndKey 6
objSelection.TypeParagraph()
Set objRange = objSelection.Range
objDoc.Tables.Add objRange, 1, 1
Set objTable = objDoc.Tables(2)
objTable.leftpadding = 0
objTable.rightpadding = 0
objTable.Columns(1).Width = objWord.CentimetersToPoints(24.00)
objTable.Cell(1, 1).Range.InlineShapes.AddPicture(strlogoBAR)
objSelection.EndKey 6
objSelection.TypeParagraph()
Set objSelection = objDoc.Range()
objSignatureEntries.Add "ATLANTICO", objSelection
objSignatureObject.NewMessageSignature = "ATLANTICO"
objSignatureObject.ReplyMessageSignature = "ATLANTICO"
objDoc.Saved = True
objWord.Quit
wscript.echo "Uma nova assinatura foi aplicada ao seu Outlook!"
Picture of problem shown below
Does anyone know why this statement
Response.write(rs.Fields.Item("password")&" ; "&rs.Fields.Item("password"))
Do this :
myPass ;
It's very strange and I'm looking for a solution since this morning. It's making me crazy because the result of this is that this codntion :
if rs("password") = rs("password") then
is False !
EDIT :
After other test, i have made an other discover :
Response.write(rs.Fields.Item("name")&" ; "&rs.Fields.Item("name"))
do :
amdin ; admin
And if i change "password" by his ordinal index it doing the same displays :
myPass ;
.
EDIT : the related code :
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=localhost; DATABASE=crm_sandbox; UID=root;PASSWORD=tahina; OPTION=3"
if Request.Form("login") <> "" or Request.Form("mdp") <> "" or Request.Form("redirect") <> "" then
Response.write(Request.Form("mdp")&" ; "&Request.Form("login")&" ; "&Request.Form("redirect")&"<br>")
if Request.Form("login") = "" then
rapport = "<p style='color: red; font-weight: bold;'>Erreur : Veuillez remplir votre nom d'utilisateur.</p>"
elseif Request.Form("mdp") = "" then
rapport = "<p style='color: red; font-weight: bold;'>Erreur : Veuillez remplir votre mot de passe.</p>"
elseif Request.Form("login") <> "" and Request.Form("mdp") <> "" then
sql = "SELECT id, mdp, nom, initiales, couleur, droit FROM connection WHERE nom='"&Request.Form("login")&"';"
Set rs = Server.CreateObject("ADODB.Recordset")
rs.open sql, conn
if rs.eof then
rapport = "<p style='color: red; font-weight: bold;'>Erreur : Nom d'utilisateur inconnu.</p>"
elseif rs("mdp") <> Request.Form("mdp") then
rapport = "<p style='color: red; font-weight: bold;'>Erreur : Mot de passe incorect.</p>"
elseif Request.Form("mdp") = rs("mdp") then
Session("util_id") = rs("id")
Session("util_nom") = rs("nom")
Session("util_couleur") = rs("couleur")
Session("util_initiales") = rs("initiales")
Session("util_droit") = rs("droit")
Session.Timeout = 660 'On créer une session de 11 heures
rapport = "<p style='color: green; font-weight: bold;'>Vous êtes à présent connecté !</p>"
if Request.Form("redirect") <> "" then
rapport = rapport&"<p>Vous allez être rédirigé vers votre page dans 3 secondes</p>"
end if
end if
end if
end if
I've actually had this issue before, when the page made it's first run, the first value of the recordset(value) returns a value, but upon second reading of recordset(value) it returned null. Or excactly what is happening with your current set up.
This is not actually a very well known issue, but there are still several support forums and questions answer along the same lines.
Example Page 1
Example Page 2
There are acouple theories that could cause this, such as, not having the correct data type in the table column data type specifier. A glitch in the recordset object that only returns the value once, and thus, must be stored in an object instead.
Because it is the second calling of the same variable that is returning Null
E.g.
' [Good Read-out] - object empties itself
if rs( "password")_
= rs("password") then
' [Bad Read-out] - object no longer contains values.
This is NOT a blanket statement occurrence, this is an anomaly, a glitch, something that doesn't have a solid reason behind it's minimal prevalence beyond the ghost in the machine.
To fix this:
Only read out the variables from the current record ONE time. This will not allow the object to empty and thus you can compare your checks later on in your code without any fuss.
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=localhost; DATABASE=crm_sandbox; UID=root;PASSWORD=tahina; OPTION=3"
if Request.Form("login") <> "" or Request.Form("mdp") <> "" or Request.Form("redirect") <> "" then
Response.write(Request.Form("mdp")&" ; "&Request.Form("login")&" ; "&Request.Form("redirect")&"<br>")
if Request.Form("login") = "" then
rapport = "<p style='color: red; font-weight: bold;'>Erreur : Veuillez remplir votre nom d'utilisateur.</p>"
elseif Request.Form("mdp") = "" then
rapport = "<p style='color: red; font-weight: bold;'>Erreur : Veuillez remplir votre mot de passe.</p>"
elseif Request.Form("login") <> "" and Request.Form("mdp") <> "" then
sql = "SELECT id, mdp, nom, initiales, couleur, droit FROM connection WHERE nom='"&Request.Form("login")&"';"
Set rs = Server.CreateObject("ADODB.Recordset")
rs.open sql, conn
'------------------------------------------------
'Place record set values in variables first.
Dim rMDP, rID, rNom, rCouleur, rInit, rDroit
rMDP = rs("mdp")
rID = rs("id")
rNom = rs("nom")
rCouleur = rs("couleur")
rInit = rs("initiales")
rDroit = rs("droit")
'------------------------------------------------
if rs.eof then
rapport = "<p style='color: red; font-weight: bold;'>Erreur : Nom d'utilisateur inconnu.</p>"
elseif rMDP <> Request.Form("mdp") then
rapport = "<p style='color: red; font-weight: bold;'>Erreur : Mot de passe incorect.</p>"
elseif Request.Form("mdp") = rMDP then
Session("util_id") = rID
Session("util_nom") = rNom
Session("util_couleur") = rCouleur
Session("util_initiales") = rInit
Session("util_droit") = rDroit
Session.Timeout = 660 'On créer une session de 11 heures
rapport = "<p style='color: green; font-weight: bold;'>Vous êtes à présent connecté !</p>"
if Request.Form("redirect") <> "" then
rapport = rapport&"<p>Vous allez être rédirigé vers votre page dans 3 secondes</p>"
end if
end if
end if
end if
Always retrieve the recordset values and place them in the variables, then manipulate them. I learned some strange issues with rs values in first days I started using classic ASP some 15 years ago.