List of Error Codes and Descriptions for OpenDSObject - vbscript

I have the following but would like to have a full list of codes and their detailed descriptions if at all possible.
For example does the username exist? Is the password wrong?
Set oADsObject = oADsNamespace.OpenDSObject(strADsPath, strUserName,strPassword, 0)
Select Case Err.number
Case 0
' Success
Session("Auth") = "YES"
Case -80070775
'Locked
errorMSG = "Account has been locked"
Case -2147943726, -2147023570, -2147024810, -2147023677, -2147022694
' Invalid
Session("Auth") = "NO"
errorMSG="Invalid details"
Case -2147023565
' Disabled
Session("Auth") = "NO"
errorMSG = "Disabled account"
Case -2147022987
'Loceked
Session("Auth") = "NO"
errorMSG = "Locked Account"
Case -2147022989, -2147023541, -2147023688
'Password expired
Session("Auth") = "NO"
errorMSG = "Password Expired"
Case else
'Something else
Session("Auth") = "NO"
errorMSG = Err.Number
end select

Related

Blank spaces are still being added to the file

When I am adding information to the file it does that all and well. It error checks the fields but at the end, adds blank spaces to the file.
This also happens if the fields are kept blank.
Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
If Char.IsNumber(txtStudentID.Text) = False Then
MessageBox.Show("Text cannot include letters or be clear, fill in correctly before proceeding",
"User Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
txtStudentID.Clear()
txtStudentID.Focus()
Else
OneMember.StudentID = txtStudentID.Text
End If
Char.IsLetter(txtName.Name)
If Char.IsLetter(txtName.Text) = False Then
MessageBox.Show("Text cannot include number or be clear, fill in correctly before proceeding",
"User Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
txtName.Clear()
txtName.Focus()
Else
'OneMember.NameOfStudent = txtName.Text
End If
Char.IsLetter(txtLesson.Name)
If Char.IsLetter(txtLesson.Text) = False Then
MessageBox.Show("Text cannot include number or be clear, fill in correctly before proceeding",
"User Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
txtLesson.Clear()
txtLesson.Focus()
Else
'OneMember.Lesson = txtLesson.Text
End If
Char.IsNumber(txtPayed.Text)
If Char.IsNumber(txtPayed.Text) = False Then
MessageBox.Show("Text cannot include letters or be clear, fill in correctly before proceeding",
"User Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
txtPayed.Clear()
txtPayed.Focus()
Else
OneMember.AmountPayed = txtPayed.Text
End If
OneMember.NameOfStudent = txtName.Text
OneMember.Lesson = txtLesson.Text
OneMember.DOl = txtDate.Text
OneMember.TOL = txtTime.Text
FileOpen(1, AddLesson, OpenMode.Random, , , Len(OneMember))
NumberOfRecords = LOF(1) / Len(OneMember)
FilePut(1, OneMember, NumberOfRecords + 1)
FileClose()
NumberOfRecords = NumberOfRecords + 1
txtStudentID.Clear()
txtName.Clear()
txtDate.Clear()
txtTime.Clear()
txtLesson.Clear()
txtPayed.Clear()
MsgBox(" Student added to file")
End Sub

Issue with VBS Join Domain on Win 7

I have the below vbs to join a Win 7 PC to the domain. On running it does not error but gives no output and does not join domain.
Can anyone see the issue and perhaps suggest how I can add error capturing?
'On Error Resume Next
strDomain = "domain.local"
strPassword = "password"
strUser = "user"
strOU = "OU=OU1,OU=OU2,OU=OU3,OU=OU with spaces in name,DC=domain,DC=local"
Const JOIN_DOMAIN = 1
Const ACCT_CREATE = 2
Const ACCT_DELETE = 4
Const WIN9X_UPGRADE = 16
Const DOMAIN_JOIN_IF_JOINED = 32
Const JOIN_UNSECURE = 64
Const MACHINE_PASSWORD_PASSED = 128
Const DEFERRED_SPN_SET = 256
Const INSTALL_INVOCATION = 262144
Set objNetwork = CreateObject("WScript.Network")
strComputer = objNetwork.ComputerName
' Join Domain
Set objComputer = GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" & _
strComputer & "\root\cimv2:Win32_ComputerSystem.Name='" & _
strComputer & "'")
ReturnValue = objComputer.JoinDomainOrWorkGroup(strDomain, _
strPassword, strDomain & "\" & strUser, strOU, _
JOIN_DOMAIN + ACCT_CREATE + DOMAIN_JOIN_IF_JOINED)
Select Case ReturnValue
Case 0 Status = "Success"
Case 2 Status = "Missing OU"
Case 5 Status = "Access denied"
Case 53 Status = "Network path not found"
Case 87 Status = "Parameter incorrect"
Case 1326 Status = "Logon failure, user or pass"
Case 1355 Status = "Domain can not be contacted"
Case 1909 Status = "User account locked out"
Case 2224 Status = "Computer Account already exists"
Case 2691 Status = "PC already on domain"
Case Else Status = "UNKNOWN ERROR " & ReturnValue
' Show Status
WScript.Echo "Join domain status: " & Status
End Select
You are setting the variable Status inside the case but the line to output it via the WScript.Echo will only show on the Case Else. To fix this move that line after the End Select so you can see the value of Status for all instances of Case.
Select Case ReturnValue
Case 0
Status = "Success"
Case 2
Status = "Missing OU"
Case 5
Status = "Access denied"
Case 53
Status = "Network path not found"
Case 87
Status = "Parameter incorrect"
Case 1326
Status = "Logon failure, user or pass"
Case 1355
Status = "Domain can not be contacted"
Case 1909
Status = "User account locked out"
Case 2224
Status = "Computer Account already exists"
Case 2691
Status = "PC already on domain"
Case Else
Status = "UNKNOWN ERROR " & ReturnValue
End Select
' Show Status
WScript.Echo "Join domain status: " & Status

Vbscript hard validation

Hy I am new to programming vbscript.I am trying to make a textbox for user in which user has to enter file version(format 1,0,0,0).user must type one integer within commas.but I failed to make a validation script to do so.. Can you please help me. Thanks in advance.I have been created this script to perform other kind of validation but I don't know how to do the validation for x,y,z,h format..
Do
dtm = InputBox("Please Enter a Numeric File version using commas", _
"File version")
Select Case True
Case isNull(dtm), (not isNumeric(dtm)), dtm = "", dtm = empty, (dtm < 1 OR dtm > 9)
MsgBox "Please enter between 1 and 9"
Case else
Exit do
End Select
Loop While True
'script on test pass
Something like this should do the job (have not tested with wscript/cscript), assuming accepted numbers are 0 to 9.
Function GetVersionNumber() As String
Dim iParts, sVersion, oTmp, dtm
iParts = 0
sVersion = ""
Do
dtm = InputBox("Please Enter a Numeric File version using commas", "File version")
For Each oTmp In Split(dtm, ",")
If IsNumeric(Trim(oTmp)) Then
If Len(sVersion) > 0 Then sVersion = sVersion & ","
sVersion = sVersion & Trim(oTmp)
iParts = iParts + 1
Else
MsgBox "Please enter between 0 and 9!" & vbCrLf & "You have typed " & oTmp
iParts = 0 ' Reset to zero accepted parts
sVersion = "" ' Reset to zero length string
End If
Next
Loop Until iParts = 4 ' x,y,z,h format <- 4 parts
GetVersionNumber = sVersion
End Function

Multiple field validation in Access VB?

I'm looking for the best way to perform a multiple-field validation on an access form. It is as simple as the field being null or not but the conditions are tricky. The criteria is not working, meaning it always moves to the else while leaving the required field(s) blank. I am a beginner in access and definitely in VB coding but here is what I have so far via google searching:
Private Sub EventSummaryPreview_Click()
If _
( _
Me.FRAUD_TYP = "Account Takeover" And _
Len([Form]![dbo_FPI_CASE_CEO Subform]![CEO_COMPANY_ID] & vbNullString) = 0 And _
Nz([Form]![dbo_FPI_CASE_TRANS Subform]![TRANS_DT], 0 & vbNullString) = 0 And _
Len([Form]![dbo_FPI_CASE_TRANS Subform]![TRANS_CEO_USER_ID] & vbNullString) = 0 And _
Nz([Form]![dbo_FPI_CASE_TRANS Subform]![TRANS_AMT], 0 & vbNullString) = 0 And _
Len([Form]![dbo_FPI_CASE_TRANS Subform]![TRANS_DEBIT_ACCT_NBR] & vbNullString) = 0 And _
Len(Me.NOTES & vbNullString) = 0 _
) Or _
( _
Me.FRAUD_TYP = "Account Takeover" And _
Len([Form]![dbo_FPI_CASE_TRANS Subform]![TRANS_DT] & vbNullString) = 0 And _
Nz([Form]![dbo_FPI_CASE_TRANS Subform]![TRANS_AMT], 0 & vbNullString) = 0 And _
Len([Form]![dbo_FPI_CASE_TRANS Subform]![TRANS_KEY] & vbNullString) = 0 And _
Len(Me.NOTES & vbNullString) = 0 _
) _
Then
MsgBox "Required enrichment data elements are not populated, please correct your data."
OK = True
Else
CurrentDb.Execute "INSERT INTO dbo_FPI_CASE_ENRICHMENT (DC_NO, ENRICH_FLG, ENRICH_FLG_TS, ENRICH_STATUS) " _
& "VALUES (" & DC_NO & ", 1, Now(), 'OPEN')"
End If
End Sub
Any help is much appreciated.
Personally, I find it incredibly worthwhile to take the time to make something like this a tad more readable. You can do this by declaring multiple boolean variables and assigning them the values instead.
Dim cond1 as boolean, cond2 as boolean
Dim cond1A as boolean, cond1B as boolean, cond1C as boolean ' etc.,
Dim cond2A as boolean, cond2B as boolean, cond2C as boolean ' etc.,
' Breaking it down 1 by 1 helps you confirm that you have all of the proper criteria
' Putting these conditions in parenthesis will allow it to evaluate as true or false
cond1A = (Me.FRAUD_TYP = "Account Takeover")
cond1B = ((Len([Form]![dbo_FPI_CASE_CEO Subform]![CEO_COMPANY_ID] & vbNullString) = 0)
cond1C = (Nz([Form]![dbo_FPI_CASE_TRANS Subform]![TRANS_DT], 0 & vbNullString) = 0)
etc.,
cond1 = (cond1A AND cond1B AND cond1C)
cond2 = (cond2A AND cond2B AND cond2C)
If cond1 or cond2 then
' If either are true then do this Action
else
' neither are true Action
endif
This may or may not have been the best way to accomplish my goal but here is the code I ended up with. I'll change to Archias' suggestion when I have another release, thanks to all who provided input!
If _
IsNull(Me.FRAUD_TYP.Value) Then
MsgBox "Required enrichment data elements are not populated, please correct your data."
OK = True
ElseIf (Me.FRAUD_TYP = "Account Takeover" And IsNull([Form]![dbo_FPI_CASE_TRANS Subform]![TRANS_KEY].Value)) Then
If Me.FRAUD_TYP = "Account Takeover" And IsNull([Form]![dbo_FPI_CASE_TRANS Subform]![TRANS_DT].Value) Then
MsgBox "Required enrichment data elements are not populated, please correct your data."
OK = True
ElseIf Me.FRAUD_TYP = "Account Takeover" And IsNull([Form]![dbo_FPI_CASE_TRANS Subform]![TRANS_CEO_USER_ID].Value) Then
MsgBox "Required enrichment data elements are not populated, please correct your data."
OK = True
ElseIf Me.FRAUD_TYP = "Account Takeover" And IsNull([Form]![dbo_FPI_CASE_CEO Subform]![CEO_COMPANY_ID].Value) Then
MsgBox "Required enrichment data elements are not populated, please correct your data."
OK = True
ElseIf Me.FRAUD_TYP = "Account Takeover" And IsNull([Form]![dbo_FPI_CASE_TRANS Subform]![TRANS_AMT].Value) Then
MsgBox "Required enrichment data elements are not populated, please correct your data."
OK = True
ElseIf Me.FRAUD_TYP = "Account Takeover" And IsNull([Form]![dbo_FPI_CASE_TRANS Subform]![TRANS_DEBIT_ACCT_NBR].Value) Then
MsgBox "Required enrichment data elements are not populated, please correct your data."
OK = True
ElseIf Me.FRAUD_TYP = "Account Takeover" And IsNull(Me.NOTES) Then
MsgBox "Required enrichment data elements are not populated, please correct your data."
OK = True
End If
ElseIf (Me.FRAUD_TYP = "Account Takeover" And Not IsNull([Form]![dbo_FPI_CASE_TRANS Subform]![TRANS_KEY].Value)) Then
If Me.FRAUD_TYP = "Account Takeover" And IsNull([Form]![dbo_FPI_CASE_CEO Subform]![CEO_COMPANY_ID].Value) Then
MsgBox "Required enrichment data elements are not populated, please correct your data."
OK = True
ElseIf Me.FRAUD_TYP = "Account Takeover" And IsNull([Form]![dbo_FPI_CASE_TRANS Subform]![TRANS_DT].Value) Then
MsgBox "Required enrichment data elements are not populated, please correct your data."
OK = True
ElseIf Me.FRAUD_TYP = "Account Takeover" And IsNull([Form]![dbo_FPI_CASE_TRANS Subform]![TRANS_AMT].Value) Then
MsgBox "Required enrichment data elements are not populated, please correct your data."
OK = True
ElseIf Me.FRAUD_TYP = "Account Takeover" And IsNull(Me.NOTES) Then
MsgBox "Required enrichment data elements are not populated, please correct your data."
OK = True
End If
Else
CurrentDb.Execute "INSERT INTO dbo_FPI_CASE_ENRICHMENT (DC_NO, ENRICH_FLG, ENRICH_FLG_TS, ENRICH_STATUS) " _
& "VALUES (" & DC_NO & ", 1, Now(), 'OPEN')"
End If

Recordset Operation is Not allowed when object is closed VBS

In the code bellow I get an error on the line reading recset.Close.
Char: 5
Error: Operation is not allowed when the object is closed.
Code: 800A0E78
Source: ADODB.Recordset
If the program reaches the line PQ_ID_number = InputBox("Enter PQ Database ID number, Do not use / ? < > \ : * | !", "PQ ID Number", "Replace Text") it seems to work fine (taking manual input) but when it tries to get the ID from the URL of a browser (automaticaly) it gives the error.
valid_name = 0
Dim objInstances, objIE, counterTab
Do While valid_name = 0 'Flag to exit the loop if the Id number has content in the SQL Database'
'-----------------------------------------------------------------------------------------'
Set objInstances = CreateObject("Shell.Application").windows
If objInstances.Count > 0 Then '/// make sure we have IE instances open.
'Loop through each tab.'
For Each objIE In objInstances
'Split the url of current tab using /'
splitURL = Split(objIE.LocationURL,"/")
'Count how many sub strings are in the URL when split'
counter = UBound(splitURL)
if counter = 7 Then
lastSplit = Split(splitURL(7),".")
lastURL = splitURL(0) & "//" & splitURL(2) & "/" & splitURL(3) & "/" & splitURL(4) & "/" & splitURL(5) & "/" & splitURL(6) & "/" & lastSplit(0)
if lastURL = "URL" Then
Set IE = objIE
counterTab = counterTab + 1
end if
end if
'End if
Next
Else
'If no internet explorer window is open.'
MsgBox "No Internet Explorer window found."
wscript.quit
End if
'Check if no [] is open in internet explorer'
if IsObject(IE) Then
url = Split(IE.LocationURL,"=")
url2 = Split(url(1),"&")
PQ_ID_number = url2(0)
else
MsgBox "No incident found."
wscript.quit
end if
'counterTab counts how many [] are open. If there is more than 1, ask for confirmation of last [] number.'
if counterTab > 1 Then
confirm = msgbox("Please confirm Incident ID: " & incidentID,vbYesNo,"Confirmation")
'If no is pressed, ask for manual entry.'
if confirm = vbNo Then
PQ_ID_number = InputBox("Enter PQ Database ID number, Do not use / ? < > \ : * | !", "PQ ID Number", "Replace Text")
On Error Resume Next
If PQ_ID_number = False Then
wscript.quit
End If
end if
end if
'-----------------------------------------------------------------------------------------'
'Open connection in Database'
dbConnectStr = "connection string"
Set con = CreateObject("ADODB.Connection")
Set recset = CreateObject("ADODB.Recordset")
con.Open dbConnectStr
'Get PQ Database title and status of incident number provided.
SQL_String = "Select title, status_id from incident_TBL where incident_ID = " & PQ_ID_number
recset.Open SQL_String, con
title = recset.Fields(0).Value
incidentStatus = recset.Fields(1).Value
con.Close
recset.Close
If title = False Then 'check if PQ_ID given has content in SQL Database
wscript.echo "Invalid PQ Database ID number, please type correct number"
valid_name = 0
Else
valid_name = 1
End If
Loop
Thanks for the help!
you need close Recordset first and only after that close connection
con.Close
recset.Close
change to:
recset.Close
con.Close

Resources