Hello everyone I'm getting some strange error, if any of you could help me out?
Error is :
Error 1 'OK' is not a member of 'Boolean?'.
Code:
If GetVer > CurrentVersion Then
GetUpd = MsgBox(ProgramName & " is an old version." & vbCrLf & "New Update is available" & _
vbCrLf & "Current version: " & CurrentVersion & vbCrLf & "Version Available: " & _
GetVer & vbCrLf & vbCrLf & "Update Now?", vbYesNo, "Update")
If GetUpd = vbYes Then
Dim sfd As New SaveFileDialog
sfd.FileName = IO.Path.GetFileName(GetVerLink)
If sfd.ShowDialog = DialogResult.OK Then
My.Computer.Network.DownloadFile(GetVerLink, sfd.FileName)
End If
End If
In WPF, ShowDialog returns a Nullable(Of Boolean), not an enum. You need to check via:
If sfd.ShowDialog = True Then
Related
I have this VBA code in MS Access (Connect, Exec and Disconnect are my own ADO subs/functions):
Private Sub cmdShipOrder_Click()
Dim intShipmentID As Integer
Dim rsShipment, rsShipmentDetail As Recordset
On Error GoTo ErrHandler
If Me.ReservationStatus <> "ZBOŽÍ KOMPLETNĚ REZERVOVÁNO" Then
MsgBox "Nejprve je nutné do objednávky rezervovat hmotné zboží.", vbCritical + vbOKOnly, "Chyba"
Exit Sub
End If
If MsgBox("Bude vytvořena expedice a celá objednávka bude označena jako expedovaná. Pokračovat?", vbExclamation + vbYesNoCancel, "Upozornění") <> vbYes Then Exit Sub
Connect
Exec "INSERT INTO tbl1Shipments (CustomerID, ShippingMethodID, ShipToID, CarrierID, ShipmentCode, DateShipped) " & _
"VALUES (" & Me.CustomerID & ", " & _
Me.ShippingMethodID & ", " & _
Me.ShipToID & ", " & _
Me.CarrierID & ", " & _
"'" & Year(Date) & "EXP" & Format(DCount("*", "dbo_tbl1Shipments", "ShipmentCode LIKE '%" & Year(Date) & "EXP%'") + 1, "000") & "', " & _
"GETDATE())"
intShipmentID = DMax("ShipmentID", "dbo_tbl1Shipments", "CustomerID=" & Me.CustomerID)
Conn.BeginTrans
Set rsShipment = CurrentDb.OpenRecordset("SELECT * FROM dbo_v_SalesOrderSub WHERE SalesOrderID=" & Me.SalesOrderID)
rsShipment.MoveFirst
Do Until rsShipment.BOF Or rsShipment.EOF
Exec "INSERT INTO tbl1ShipmentDetails (ShipmentID, SalesOrderDetailID, Quantity) " & _
"VALUES (" & intShipmentID & ", " & _
rsShipment("SalesOrderDetailID") & ", " & _
rsShipment("Quantity") & ")"
rsShipment.MoveNext
Loop
Set rsShipmentDetail = CurrentDb.OpenRecordset("SELECT * FROM dbo_v_ShipmentSub WHERE ShipmentID=" & intShipmentID)
rsShipmentDetail.MoveFirst
Do Until rsShipmentDetail.BOF Or rsShipmentDetail.EOF
If rsShipmentDetail("ProductTypeID") <> 3 Then
Exec "UPDATE tbl1Units " & _
"SET ShipmentDetailID=" & rsShipmentDetail("ShipmentDetailID") & " " & _
"WHERE SalesOrderDetailID=" & rsShipmentDetail("SalesOrderDetailID")
End If
rsShipmentDetail.MoveNext
Loop
Conn.CommitTrans
rsShipment.Close
Set rsShipment = Nothing
rsShipmentDetail.Close
Set rsShipmentDetail = Nothing
Disconnect
Exit Sub
ErrHandler:
MsgBox "CHYBA: " & Err.Description
Conn.RollbackTrans
Exec "DELETE FROM tbl1Shipments WHERE ShipmentID=" & intShipmentID
If Not rsShipment Is Nothing Then
rsShipment.Close
Set rsShipment = Nothing
End If
If Not rsShipmentDetail Is Nothing Then
rsShipmentDetail.Close
Set rsShipmentDetail = Nothing
End If
Disconnect
When I run this without Conn.BeginTrans and Conn.CommitTrans, the code works just fine. However when I leave the transaction commands there, I get a "query timeout" error from SQL Server. Specifically on a second cycle in the INSERT INTO tbl1ShipmentDetails statement. Why?
Update - 2/14/21
Ok, this is where I'm at now. the code below works! Yay! However, there are no records in the database to read.
''''
<%
db_server = "my_server"
db_name = "my_db-name"
db_username = "my_username"
db_userpassword = "my_password"
db_fieldname = "my_fieldname"
db_tablename = "my_tablename"
db_schema = "my_schema"
'Establish a connection to the database
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open("Provider=SQLOLEDB; Data Source=" & db_server & "; Inital catalog=" & db_name & "; User ID=" & db_username & "; password=" & db_userpassword & ";")
'Test the connection to make sure it is available and it's open.
If IsObject(conn) then
response.write "The connection is active!<br />"
if conn.State = 1 then
response.write "A connection is made, and is open.<br />"
end if
end if
'Query the tables I need
Set rs= conn.execute("SELECT * FROM [" & db_name & "].[" & db_schema & "].[" & db_tablename & "]")
do until rs.EOF
count = count + 1
for each x in rs.Fields
Response.Write(x.name)
Response.Write(" = ")
Response.Write(x.value & "<br>")
next
Response.Write("<br>")
rs.MoveNext
loop
Set conn = nothing
response.write "Records found = " & count
%>
''''
So with the part above is actually working again. I set out to add a record to the database with the code below. It seems to work as it does not cause an error. However, it is not adding the record though.
''''
<%
db_server = "my_server"
db_name = "my_db-name"
db_username = "my_username"
db_userpassword = "my_password"
db_fieldname = "my_fieldname"
db_tablename = "my_tablename"
db_schema = "my_schema"
count = 0
'Establish a connection to the database
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open("Provider=SQLOLEDB; Data Source=" & db_server & "; Inital catalog=" & db_name & "; User ID=" & db_username & "; password=" & db_userpassword & ";")
'Test the connection to make sure it is available and it's open.
If IsObject(conn) then
response.write "The connection is active!<br />"
if conn.State = 1 then
response.write "A connection is made, and is open.<br />"
end if
end if
sql="INSERT INTO " & db_name & "." & db_schema & "." & db_tablename & " (fname,lname,email,upassword)"
sql=sql & " VALUES "
sql=sql & "('John',"
sql=sql & "'Doe',"
sql=sql & "'JohnD#email.com',"
sql=sql & "'12345')"
on error resume next
conn.Execute sql,recaffected
if err<>0 then
Response.Write("No update permissions!")
else
Response.Write("<h3>" & recaffected & " record added</h3>")
end if
conn.close
Set conn = nothing
%>
''''
This is where I have been stuck. It is not writing to the database. It just runs and nothing gets done. If I remove the resume next portion, it still works with no error but, still, no record being written cause the resume next. I have tried two different users to run the code. Both of which have read and write permission. Now what? I'll just keep trying until someone puts me out of my misery... lol!
Well, it seems a friend and I finally found out what was going on. The code actually works but, for some reason, the database's ID field is not auto-incrementing. So, in order to add a record, we had to first check to see how many records are in the DB then add 1 to the count to use for our new records id. Seems every solution leads to a new issue. That's programing...
Just in case any of that makes sense or even if it doesn't make sense, here the id's properties.
ID (PK, uniqueidentifier, not null)
db_server = "my_server"
db_name = "my_db-name"
db_username = "my_username"
db_userpassword = "my_password"
db_fieldname = "my_fieldname"
db_tablename = "my_tablename"
db_schema = "my_schema"
count = 0
'Establish a connection to the database
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open("Provider=SQLOLEDB; Data Source=" & db_server & "; Inital
catalog=" & db_name & "; intergaraded security = false ; User ID=" &
db_username & "; password=" & db_userpassword & ";")
'Test the connection to make sure it is available and it's open.
'If IsObject(conn) then
' response.write "The connection is active!<br />"
' if conn.State = 1 then
' response.write "A connection is made, and is open.<br />"
' end if
'end if
Set rs= conn.execute("Select top 1 id from " & db_name & "." & db_schema & "." & db_tablename & " order by id desc")
on error resume next
do until rs.EOF
for each x in rs.Fields
count = x.value
'response.write x.value & "<br>"
next
rs.MoveNext
loop
'conn.Execute sql,recaffected
if err<>0 then
Response.Write("<br>id: " & err.description)
else
'Response.Write("<h3>" & count & " record in db</h3>")
end if
'conn.close
Set rs= conn.execute("Select top 1 id from " & db_name & "." & db_schema & "." & db_tablename & " order by id desc")
sql=sql & " VALUES "
sql=sql & "(" & cstr(count + 1) & ","
sql=sql & "'John',"
sql=sql & "'Doe',"
sql=sql & "'user#website.com',"
sql=sql & "'1234abcd')"
'response.write sql & "<br>"
on error resume next
conn.Execute sql,recaffected
if err<>0 then
Response.Write("<br>insert: " & err.description)
else
'Response.Write("<br>" & recaffected & " record added</h3>")
end if
conn.close
Set conn = nothing
I left all the error checking in there but, it is all commented out. I hope this is the last time I have to come back to this. Goodluck!
I created a copy button in an Access form to copy the Data in the fields that users enter so they can paste it in an internal system.
I created VBA code "on the click:
Private Sub Command6_Click()
On Error GoTo Err_cmdDuplicate_Click
DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdCopy
Exit_cmdDuplicate_Click:
Exit Sub
Err_cmdDuplicate_Click:
MsgBox Err.Description
Resume Exit_cmdDuplicate_Click
End Sub
I am having 2 problems:
it copies all the data with the headers but pastes it vertically rather than horizontally. I guess it needs to be formatted. I have to add since the code was grabbing everything in the form even the information that I didn't want. I created a query then a report based on the query then made the copy button with the code behind it.
this is the code
Private Sub cmdCopy_Click()
On Error GoTo Err_cmdDuplicate_Click
'Copies values from agent entered data fields into
'required format for TAS and copies to
'system clipboard.
'control name and type are as follows:
'CboTeam
'CboTax
'TboCallBack
'TboCaller
'TboBusName
'CboAuthType
'TboAuthID
'CboContact
'TboDetail
'TboBal
'TboDelqs
Application.Echo False
Me.PasteBox.Visible = True
Me!PasteBox.Value = _
"Team: " & Me!CboTeam & vbNewLine & _
"Tax Type: " & Me!CboTax & vbNewLine & _
"Phone: " & Me!TboCallBack & vbNewLine & _
"Caller: " & Me!TboCaller & vbNewLine & _
"Business Name: " & Me!TboBusnAME & vbNewLine & _
"Authentication Method: " & Me!CboAuthType & vbNewLine & _
"Authentication ID: " & Me!TboAuthID & vbNewLine & _
"Contact Reason: " & Me!CboContact & vbNewLine _
& vbNewLine & _
"Call Detail:" & vbNewLine & _
Me!TboDetail & vbNewLine _
& vbNewLine & _
"Balance: " & Me!TboBal & vbNewLine & _
"Delinquent Periods: " & Me!TboDelqs
Me.PasteBox.SetFocus
DoCmd.RunCommand acCmdCopy
Me.cmdcopy.SetFocus
Me.PasteBox.Visible = False
Application.Echo True
Exit_cmdDuplicate_Click:
Exit Sub
Application.Echo True
Err_cmdDuplicate_Click:
MsgBox Err.Description
Application.Echo True
Resume Exit_cmdDuplicate_Click
Application.Echo True
End Sub
I am opening an SQL Server Connection in EXCEL VBA and on the objMyCmd.Execute line when it is using the SQL script I am getting this error message:
"Run-time error '-2147217900 (80040e14)') Automation error"
I have reviewed other SO posts that seem to reference an issue with the connection string itself, but I don't believe that is the issue as I am able to pull the first few variables listed when eliminating the rest of the SQL script.
I have attempted to review the SQL code to see if I am using an incorrect format, or if the language is not written properly and I am not able to determine the issue. I am hoping with some Q & A we may notice something I have missed in how this is written? Please let me know if there is additional information I can provide, below is the code up to the point of error.
Sub SQL_GetAgentChart()
Dim dtDate As Date
Dim myTable As ListObject
Dim DataServer As String
Dim Database As String
Dim constring As String
DataServer = "GLSSQLMADP2"
Database = "PERF_MGMT_BWRSRV_PROD"
constring = "Driver={SQL Server};Server=" & DataServer & "; Database=" & Database & "; Trusted_Connection=yes"
Dim AVStartDate As Date
Dim AVEndDate As Date
Dim RepID As Long
'Declare variables'
Set objMyConn = New ADODB.Connection
Set objMyCmd = New ADODB.Command
Set objMyRecordset = New ADODB.Recordset
Set myTable = Worksheets("Witness").ListObjects("tblWitness")
AVStartDate = DateValue("Mar 01, 2016")
AVEndDate = DateValue("Mar 31, 2016")
RepID = 2040
'Open Connection'
objMyConn.ConnectionString = constring
objMyConn.Open
'Set and Excecute SQL Command'
Set objMyCmd.ActiveConnection = objMyConn
objMyCmd.CommandText = " " & _
"SELECT PERSN_XTRNL_ID_NR, SOURCE, LOGGINGTS, DD7, CUREREASON, CUREDATE, LNSTATUS " & _
"FROM TTB " & _
"WITH INCALL AS (SELECT T.CUREREASON, CUREVALUE " & _
"FROM TTB T " & _
"JOIN PERSONNEL P ON T.PERSONNELID = P.PERSONNELID " & _
"LEFT JOIN CURETRANSLATE C ON T.CUREREASON = C.CUREREASON AND T.LNSTATUS = C.STATUS " & _
"WHERE T.PERSONNELID = " & RepID & " " & _
"AND LOGGINGTS > '" & AVStartDate & "' " & _
"AND LOGGINGTS < '" & AVEndDate + 1 & "' " & _
"AND INCOMING = 1 " & _
"AND DD7 > 0), OUTCALL AS (SELECT T.CUREREASON, CUREVALUE " & _
"FROM TTB T " & _
"JOIN AVAYA A ON T.UID = A.TTBUID " & _
"LEFT JOIN CURETRANSLATE C ON T.CUREREASON = C.CUREREASON AND T.LNSTATUS = C.STATUS " & _
"WHERE PERSONNELID = " & RepID & " " & _
"AND LOGGINGTS > '" & AVStartDate & "' " & _
"AND LOGGINGTS < '" & AVEndDate + 1 & "' " & _
"AND INCOMING = 0 " & _
"AND A.AVAYAGROUP IN ('15', '1A', '1B', '1C', '1D', '1E', '1F', '1G', '1H') " & _
"AND DD7 > 0) "
objMyCmd.CommandType = adCmdText
objMyCmd.Execute
Hey all i am trying to get a connection to my SQL server version 10.50.2500 in Classic ASP
My code in the .asp page is (including all connection strings I've tried using):
Set objConn = Server.CreateObject("ADODB.Connection")
Set objRS = Server.CreateObject("ADODB.Recordset")
'objConn.ConnectionString = "Provider={SQL Server};Server=xxx.xxx.xxx.xxx\SQLEXPRESS;Database=JForm;User ID=xxxx;Pwd=xxxx"
'objConn.ConnectionString = "Driver={SQL Server};Server=xxx.xxx.xxx.xxx\SQLEXPRESS;Database=JForm;Uid=xxxx;Pwd=xxxx;"
'objConn.ConnectionString = "Provider=SQLNCLI10;Server=xxx.xxx.xxx.xxx,1433;Database=JForm;Uid=xxxx;Pwd=xxxx;Persist Security Info=True"
'objConn.ConnectionString = "Provider=SQLNCLI;Server=.\SQLEXPRESS;Database=JForm;Uid=xxxx;Pwd=xxxx"
objConn.ConnectionString = "Driver={SQL Server Native Client 10.0};Server=xxx.xxx.xxx.xxx\SQLEXPRESS;Database=JForm;Uid=xxxx;Pwd=xxxx"
strSQL = "UPDATE jURLS " & _
"SET rssFeedURL = 'http://www.xxxx.com/rss/" & rss & "'," & _
"csvURL = 'http://www.xxxx.com/csv/" & csv & "'," & _
"jFormName = '" & forname & "'," & _
"isActive = " & active & " " & _
"WHERE jFormName = '" & forname & "'"
objConn.open
objRS.Open strSQL, objConn, 1,3
'If Not objRS.EOF Then
'iterate through records here
'Else
'no records found
'End If
objRS.close
Set objRS=Nothing
objConn.close
Set objConn=Nothing
It seems to crash on the objConn.open. However, it only gives me a 500 - Internal server error. and not an error thats helpful!
Once i take the database code from the page and leave everything else, it works without the 500 - Internal server error being displayed.
What else can i try in order to get this to work?
you have an extra comma here :
"isActive = " & active & "," & _
change it to:
"isActive = " & active & " " & _
about the connection error, try debugging using the connection.errors collection
On Error Resume Next
objConn.open
for each errobj in objConn.Errors
Response.write errobj.Number & "<br />"
Response.write errobj.Description & "<br />"
next
On Error Goto 0
Try:
response.write(strSQL) <-- this will allow you to look at your current SQL statement and see if it makes sense.
set objRS = objConn.execute(strSQL)