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
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?
I need to recurse a folder and all subfolders and move the pdf files to another folder. Looking here I tried the below but it seems to continuously run (the script never ends) but it does move the files.
I would also like to count the source files, recurse folder and move pdf (ignore case) files, count destinations files. If source and destination are equal then run dir *.pdf > trust.csv and send a success email
Set fso = CreateObject("Scripting.FileSystemObject")
Set Message = CreateObject("CDO.Message")
Set Shell = WScript.CreateObject("WScript.Shell")
Set shell = CreateObject("Wscript.shell")
'Specify variables for Emails
strScriptServer = "ASFOXTECHOPS01"
strScriptPath = "\\techopspc01\c$\scripts\WM..."
strScriptName = "[WM-01]-WMScansToCenterDoc.vbs"
'strToEmail = ""
strCCEmail = ""
strCCEmailFail = ""
strProcessID = "[WM-01]"
strCustomerImpact = "LOW"
strCorporateImpact = "LOW"
strDocumentation = "\\FSCHAFOX01\GROUP_SHARE\Tech Group\Documentation\Automation\"
blnEmailNotification = false
'Specify variables for File Paths
'strFromPath1 = "\\fschauni01\GROUP_SHARE\Wealth Management\Scanning\ZAstrosky\"
strToPath1 = "\\fschauni01\GROUP_SHARE\Wealth Management\Tech\"
strToArchive1 = "\\fschauni01\GROUP_SHARE\Wealth Management\Scanning\" & StrYear & "_" & strMonth
'BROKE************CREATE ARCHIVE FOLDER IF IT DOES NOT EXIST
'If FSO.FolderExists(strToArchive1) Then
'Proceed
'Else
' FSO.CreateFolder("\\fschauni01\GROUP_SHARE\Wealth Management\Scanning\" & StrYear & "_" & strMonth)
'End If
'DELETE FILES FROM THE strToPath(s) TO AVOID OVERWRITE ERRORS
FSO.DeleteFile (strToPath1 & "*.*")
testfolder = "\\fschauni01\GROUP_SHARE\Wealth Management\Tech\"
MoveFiles fso.GetFolder("\\fschauni01\GROUP_SHARE\Wealth Management\Scanning\ZAstrosky")
blnEmailNotification = True
'Email
'If Err <> 0 Then
' blnEmailNotification = false
' HandleError
'End If
If blnEmailNotification = True Then
'Send Results email
objMessage.Subject = "SUCCESS - " & strProcessID & " - WM Scanned Reports Imported into CenterDoc"
objMessage.From = "IT Automation"
objMessage.Sender = ""
'objMessage.To = strToEmail
objMessage.Cc = strCCEmail
objMessage.TextBody = "---------------SCRIPT SUCCESSFUL---------------" & vbnewline & VbCrLf & "Script successfully moved the files with no errors." & vbnewline & vbcrlf & "- Script Name:" & VbTab & VbTab & VbTab & strScriptName & VbNewLine & VbCrLf & "- Script Origination:" & VbTab & VbTab & strScriptServer & VbNewline & VbCrLf & "- Script Path:" & VbTab & VbTab & VbTab & strScriptPath & VbNewLine & VbCrLf & "- Documentation:" & VbTab & VbTab & strDocumentation & VbNewLine & VbCrLf & "- Set1:" &VbTab & VbTab & "Souce Files = " & sourcecount1 & VbTab & VbTab & "Destination Files = " & destcount1 & VbTab & VbTab & "Archive Files = " & archivecount1 & VbTab & VbTab & "------------------------------------------------------------"
objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = ""
objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objMessage.Configuration.Fields.Update
objMessage.Send
Else
'Do Nothing
End If
Sub HandleError
strErrorMessage = "Error Number " & Err.Number & ":" & Err.Description
objMessage.Subject = "SCRIPT ERROR - " & strProcessID & " - IMMEDIATE ACTION REQUIRED"
objMessage.From = "IT Automation"
objMessage.Sender = ""
objMessage.To = strToEmail
'objMessage.Cc = strCCEmail
objMessage.TextBody = "---------------SCRIPT ERROR---------------" & vbnewline & VbCrLf & "Script Name:" & VbTab & VbTab & VbTab & strScriptName & VbNewLine & VbCrLf & "Customer Impact:" & VbTab & VbTab & VbTab & strCustomerImpact & VbNewLine & VbCrLf & "Corporate Impact:" & VbTab & VbTab & VbTab & strCorporateImpact & VbNewLine & VbCrLf & "Error Description:" & VbTab & VbTab & VbTab & Err.Description & vbnewline & VbCrLf & "Error Number:" & VbTab & VbTab & VbTab & Err.Number & VbCrLf & VbNewLine & "Script Location:" & VbTab & VbTab & VbTab & strScriptServer & VbCrLf & VbNewLine & "Script Path:" & VbTab & VbTab & VbTab & strScriptPath & VbNewline & VbCrLf & "Documentation:" & VbTab & VbTab & strDocumentation & VbNewLine & VbCrLf & "-------------------------------------------------"
objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = ""
objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objMessage.Configuration.Fields.Update
objMessage.Send
Err.Clear
End Sub
Sub MoveFiles(fldr)
For Each f In fldr.Files
basename = fso.GetBaseName(f)
extension = fso.GetExtensionName(f)
If LCase(extension) = "pdf" Then
dest = fso.BuildPath(testfolder, f.Name)
Do While fso.FileExists(dest)
dest = fso.BuildPath(testfolder, basename & "." & extension)
Loop
f.Move dest
End If
Next
For Each sf In fldr.SubFolders
MoveFiles sf
Next
End Sub
Edited original code for more help.
thanks Zoyd
astro
You move all the pdf files from \\fschauni01\GROUP_SHARE\Wealth Management\Scanning\ZAstrosky and its subfolders to \\fschauni01\GROUP_SHARE\Wealth Management\Scanning\ZAstrosky\Tech. Your recursion logic is sound, but there is another problem: your destination folder is a subfolder of your source folder. Thus, your script keeps copying files from \\fschauni01\GROUP_SHARE\Wealth Management\Scanning\ZAstrosky\Tech to itself. Whether this works or not, it is a bad idea to do a foreach loop on a collection and modify its content.
The main problem is that this while loop will never end if it is taken at all, and in this case, it is taken. When your recursion reaches the destination folder, all the files already exist in the destination folder (obviously), the loop is taken and there is no way out of it.
If LCase(extension) = "pdf" Then
dest = fso.BuildPath(testfolder, f.Name)
Do While fso.FileExists(dest)
dest = fso.BuildPath(testfolder, basename & "." & extension)
Loop
f.Move dest
End If
As for the matter of counting files, does folder.Files.Count not work ? (if you need a recursive count, I'am afraid you'll have to do it yourself, but you know how).
After your edit, the code still contains this:
Do While fso.FileExists(dest)
dest = fso.BuildPath(testfolder, basename & "." & extension) ' ☠
Loop
So, for example, if a file a.pdf exists in "\\fschauni01\GROUP_SHARE\Wealth Management\Scanning\ZAstrosky\docs1" and in "\\fschauni01\GROUP_SHARE\Wealth Management\Scanning\ZAstrosky\docs2", your script will find that a.pdf already exists in the archive directory and enters the infinite loop. A way around this is to recreate the directory structure in the archive directory (each time you call MoveFiles on directoryA, create directoryA in the archive directory and move files there).
I'm working with an SQL Server and I'm create a program to add records to the database. However, the database's field for the Dates of Births isn't being accepted.
At the server side, the data type is 'Date' on MS Express SQL Server that should be YYYY-MM-DD. However, when trying to 'upload' the new records from the program the dates are being rejected. I know it's down to how I'm formatting them and particularly I know it's literally just two lines of code; But I can't get it going!
SQL = "Insert into PersonsA(Members_ID," & _
"Gamer_Tag," & _
"Screenname," & _
"First_Name," & _
"Last_Name," & _
"DoB," & _
"E_Mail_Address," & _
"Position," & _
"U_G_Studio," & _
"Cautions," & _
"Record," & _
"Event_Attendance," & _
"Member_Status) values('" & Me.midtxt.Text.Trim & "'," & _
"'" & Me.gttxt.Text.Trim & "'," & _
"'" & Me.sntxt.Text.Trim & "'," & _
"'" & Me.fntxt.Text.Trim & "'," & _
"'" & Me.lntxt.Text.Trim & "'," & _
"" & Val(Me.dobtxt.Text) & "" & _ 'THIS IS THE DATES OF BIRTHS
"'" & Format(Me.dobtxt.Text, "YYYY-MM-DD") & "'," & _ 'THIS IS FORMATTING
"'" & Me.emailtxt.Text.Trim & "'," & _
"'" & Me.teamptxt.Text.Trim & "'," & _
"'" & Me.ugptxt.Text.Trim & "'," & _
"'" & Me.ugctxt.Text.Trim & "'," & _
"'" & Me.recordtxt.Text.Trim & "'," & _
"'" & Me.eventatxt.Text.Trim & "'," & _
"'" & Me.Mstattxt.Text.Trim & "')"
So as you can see the two lines I'm having trouble are:
"" & Val(Me.dobtxt.Text) & "" & _
"'" & Format(Me.dobtxt.Text, "YYYY-MM-DD") & "'," & _
I know it'll be something really stupid, but I'm newish to programming.
Reject your command string and start using SqlParameter.
Dim conn As New SqlConnection("conStr")
Dim cmd As SqlCommand = conn.CreateCommand()
cmd.CommandText = "INSERT INTO [PersonsA] ([Members_ID], [Gamer_Tag]) VALUES (#Members_ID, #Gamer_Tag);"
cmd.Parameters.AddWithValue("#Members_ID", Me.midtxt.Text.Trim) '<- If Int type change to: Integer.Parse(Me.midtxt.Text.Trim)
cmd.Parameters.AddWithValue("#Gamer_Tag", Me.gttxt.Text.Trim)
conn.Open()
cmd.ExecuteNonQuery()
Date column example:
cmd.Parameters.AddWithValue("#MY_DATE_PARAM", Date.Parse(Me.dateTextBox.Text.Trim))
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
This question already has an answer here:
Access VBA - Identifying text
(1 answer)
Closed 8 years ago.
I have a form and subform. Im trying to allow updates in the subform with the use of buttons. However my code is giving me.
KEY_ID is text, the other two are number types.
"Syntax error in query expression "5", ROOM=5. DRAWER=55 (this is the new value i tried to change it to) WHERE KEY_ID=5'.
This is an image of my form: http://jumpshare.com/b/17A7Pr
This is what im trying:
Private Sub cmdAdd_Click()
If Me.keyID.Tag & "" = "" Then
CurrentDb.Execute "INSERT INTO KEYS(KEY_ID, ROOM, DRAWER)" & _
" VALUES('" & Me.keyID & "'," & Me.roomID & "," & Me.drawerID & ")"
subKey.Form.Requery
Else
CurrentDb.Execute "UPDATE KEYS " & _
" SET KEY_ID=" & Chr(39) & keyID & Chr(39) & _
", ROOM=" & Me.roomID & _
", DRAWER=" & Me.drawerID & _
" WHERE KEY_ID=" & Me.keyID.Tag
Debug.Print KEY_ID
End If
Solution:
CurrentDb.Execute "UPDATE KEYS " & _
" SET KEY_ID=" & Me.keyID & _
", ROOM=" & Me.roomID & _
", DRAWER=" & Me.drawerID & _
" WHERE KEY_ID=" & Chr(39) & keyID.Tag & Chr(39)
Solution:
CurrentDb.Execute "UPDATE KEYS " & _
" SET KEY_ID=" & Me.keyID & _
", ROOM=" & Me.roomID & _
", DRAWER=" & Me.drawerID & _
" WHERE KEY_ID=" & Chr(39) & keyID.Tag & Chr(39)
Try the code without Chr(39).. This should work.
Private Sub cmdAdd_Click()
If Me.keyID.Tag & "" = "" Then
CurrentDb.Execute "INSERT INTO KEYS(KEY_ID, ROOM, DRAWER)" & _
" VALUES('" & Me.keyID & "'," & Me.roomID & "," & Me.drawerID & ")"
subKey.Form.Requery
Else
CurrentDb.Execute "UPDATE KEYS " & _
" SET KEY_ID=" & keyID & _
", ROOM=" & Me.roomID & _
", DRAWER=" & Me.drawerID & _
" WHERE KEY_ID=" & Me.keyID.Tag
Debug.Print KEY_ID
End If