Found this Reboot Vista.vbs script on a number of forums. Seems like the whole post ( text including the code ) was posted on many forums. So I don't know who the original author is. Heres the code here:
Option Explicit
On Error Resume Next
Dim Wsh, Time1, Time2, Result, PathFile, MsgResult, MsgA, AppName, KeyA, KeyB, TimeDiff
MsgA = "Warning! Close all running programs and click on OK."
KeyA = "HKEY_CURRENT_USER\Software\RestartTime\"
KeyB = "HKEY_CURRENT_USER\Software\Microsoft\Windows\Curr e ntVersion\Run\RestartTime"
AppName = "Boot Up Time"
Set Wsh = CreateObject("WScript.Shell")
PathFile = """" & WScript.ScriptFullName & """"
Result = wsh.RegRead(KeyA & "Times")
if Result = "" then
MsgResult = Msgbox (MsgA, vbOKCancel, AppName)
If MsgResult = vbcancel then WScript.Quit
Wsh.RegWrite KeyA & "Times", left(Time,8), "REG_SZ"
Wsh.RegWrite KeyB, PathFile, "REG_SZ"
Wsh.Run "cmd /c Shutdown -r -t 00", false, 0
else
Wsh.RegDelete KeyA & "Times"
Wsh.RegDelete KeyA
Wsh.RegDelete KeyB
TimeDiff = DateDiff("s",Result,left(Time,8))
MsgBox "Your system reboots in " & TimeDiff & " seconds", VbInformation, AppName
end if
wscript.Quit
It is supposed to reboot Vista, and once it is rebooted, show the time it took to reboot.
It reboots fine and everything, but the dialog box doesn't pop up. I have to manually click on the script again for the time to appear ? I think that defeats the purpose of the script don't you ?
Any help would be much appreciated fellas.
You cannot have spaces in the regpath: Change "Curr e ntVersion" to "CurrentVersion"
This row:
Wsh.RegWrite KeyB, PathFile, "REG_SZ"
will register the script to autostart with windows if the PathFile and KeyB is correct, but with spaces in "Curr e ntVersion" it will not work.
Maybe you are getting an error which is preventing the display of the message box? This line you have at the start of the script will cause it to ignore all errors:
On Error Resume Next
You should simply delete this line, then run it again and see what is happening.
Related
I'm currently building a form where a user can look up a tool based on the description or part number.
I want user to be able to type any letters into the combobox that I have tied to a query listing all my tools and the combobox will repopulate itself with the tools most similar to what is present in their combobox. For example, if they start typing wre, then tools that have similar characters will start appearing in the combobox such as wrench, torque wrench, power wrench, etc.
I've tried looking around for other people's solutions to this but either I didn't fully comprehend the existing solution (I'm fairly new to Access) or it wasn't what I was looking for. I've seen that people suggested using a listbox instead but I really don't want to go down that route.
I was thinking about using what the user types in the combobox and my VBA code will pick up the "change event" and requery the combobox on the fly by using their input as the like criteria for the new query.
Is this a possible route? Will it be slower? Is there a better route?
I'm hoping someone can show some examples on how to achieve what I'm looking for.
The search as you type feature is very useful! With a textbox and a listbox, you can setup a dynamic search tool that will filter a list for approximate matches as you type. The textbox has four events associated with it, as seen here.
The code behind the form looks like this. Pay attention to the part in bold. This is where we create a string of SQL commands, and utilize the SQL Like operator, to get dynamic matches as we type. Pay attention to the text in bold below.
Option Compare Database
Option Explicit On
Private blnSpace As Boolean 'INCLUDE THIS LINE ON YOUR FORM
Private Sub btnClearFilter_Click()
'CODE FOR THE RED "X" BUTTON TO CLEAR THE FILTER AND SHOW ALL
On Error Resume Next
Me.txtSearch.Value = ""
txtSearch_Change()
End Sub
Private Sub txtSearch_Change()
'CODE THAT HANDLES WHAT HAPPENS WHEN THE USER TYPES IN THE SEARCH BOX
Dim strFullList As String
Dim strFilteredList As String
If blnSpace = False Then
Me.Refresh 'refresh to make sure the text box changes are actually available to use
'specify the default/full rowsource for the control
strFullList = "SELECT RecordID, First, Last FROM tblNames ORDER BY First;"
'specify the way you want the rowsource to be filtered based on the user's entry
strFilteredList = "SELECT RecordID, First, Last FROM tblNames WHERE [First] LIKE ""*" & Me.txtSearch.Value &
"*"" OR [Last] LIKE ""*" & Me.txtSearch.Value & "*"" ORDER BY [First]"
'run the search
fLiveSearch Me.txtSearch, Me.lstItems, strFullList, strFilteredList, Me.txtCount
End If
End Sub
Private Sub txtSearch_KeyPress(KeyAscii As Integer)
'NECESSARY TO IDENTIFY IF THE USER IS HITTING THE SPACEBAR
'IN WHICH CASE WE WANT TO IGNORE THE INPUT
On Error GoTo err_handle
If KeyAscii = 32 Then
blnSpace = True
Else
blnSpace = False
End If
Exit Sub
err_handle:
Select Case Err.Number
Case Else
MsgBox "An unexpected error has occurred: " & vbCrLf & Err.Description &
vbCrLf & "Error " & Err.Number & "(" & Erl() & ")"
End Select
End Sub
Private Sub txtSearch_GotFocus()
' USED TO REMOVE THE PROMPT IF THE CONTROL GETS FOCUS
On Error Resume Next
If Me.txtSearch.Value = "(type to search)" Then
Me.txtSearch.Value = ""
End If
End Sub
Private Sub txtSearch_LostFocus()
' USED TO ADD THE PROMPT BACK IN IF THE CONTROL LOSES FOCUS
On Error Resume Next
If Me.txtSearch.Value = "" Then
Me.txtSearch.Value = "(type to search)"
End If
End Sub
Finally, in a regular module, you will need this script.
Option Compare Database
Option Explicit On
'************* Code Start **************
' This code was originally written by OpenGate Software
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
' OpenGate Software http://www.opengatesw.net
Function fLiveSearch(ctlSearchBox As TextBox, ctlFilter As Control,
strFullSQL As String, strFilteredSQL As String, Optional ctlCountLabel As Control)
Const iSensitivity = 1 'Set to the number of characters the user must enter before the search starts
Const blnEmptyOnNoMatch = True 'Set to true if you want nothing to appear if nothing matches their search
On Error GoTo err_handle
'restore the cursor to where they left off
ctlSearchBox.SetFocus
ctlSearchBox.SelStart = Len(ctlSearchBox.Value) + 1
If ctlSearchBox.Value <> "" Then
'Only fire if they've input more than two characters (otherwise it's wasteful)
If Len(ctlSearchBox.Value) > iSensitivity Then
ctlFilter.RowSource = strFilteredSQL
If ctlFilter.ListCount > 0 Then
ctlSearchBox.SetFocus
ctlSearchBox.SelStart = Len(ctlSearchBox.Value) + 1
Else
If blnEmptyOnNoMatch = True Then
ctlFilter.RowSource = ""
Else
ctlFilter.RowSource = strFullSQL
End If
End If
Else
ctlFilter.RowSource = strFullSQL
End If
Else
ctlFilter.RowSource = strFullSQL
End If
'if there is a count label, then update it
If IsMissing(ctlCountLabel) = False Then
ctlCountLabel.Caption = "Displaying " & Format(ctlFilter.ListCount - 1, "#,##0") & " records"
End If
Exit Function
err_handle:
Select Case Err.Number
Case 91 'no ctlCountLabel
'exit
Case 94 'null string
'exit
Case Else
MsgBox "An unexpected error has occurred: " & vbCrLf & Err.Description &
vbCrLf & "Error " & Err.Number & vbCrLf & "Line: " & Erl()
End Select
End Function
The code comes from this link:
http://www.opengatesw.net/ms-access-tutorials/Access-Articles/Search-As-You-Type-Access.html
Stressed out manager trying to fix a problem in our organisational CRM.
We have a macro set up to send 'ad hoc' text messages to clients. The character limit for the text input is 160, and if you exceed that, a msgbox pops up to tell you to reduce your text by x characters.
When you hit OK, it then kills the entire input box (so you have to re-type a new shorter version of your original message).
How can I set it up so that if you exceed the character limit, it tells you and then gives you the opportunity to go back and delete a few characters?
This is the portion of code I think is relevant:
set msgEntryDlg = CreateDialog("Adhoc SMS")
set msgTxtCtl = msgEntryDlg.AddControl("SMS Message: ",2, "")
if NOT msgEntryDlg.Execute then
Msgbox "Message cancelled!"
Exit sub
end if
mail_message = msgTxtCtl.Text
mail_message = " " + mail_message
If Len(mail_message) < 1 Then
MsgBox "Message was empty, please enter a message!"
Exit Sub
End If
If Len(mail_message) > 160 Then
MsgBox "Message is too long, please reduce by " & (len(mail_message) - 160) & " characters.",4112
Exit Sub
End If
I think it's something to do with a loop ... but I am clueless!
Thanks in advance.
Untested, but I believe you're looking for something like this:
Dim success As Boolean
Do
Set msgEntryDlg = CreateDialog("Adhoc SMS")
Set msgTxtCtl = msgEntryDlg.AddControl("SMS Message: ", 2, "")
If Not msgEntryDlg.Execute Then
MsgBox "Message cancelled!"
Exit Do
End If
mail_message = msgTxtCtl.Text
mail_message = " " + mail_message
If Len(mail_message) < 1 Then
MsgBox "Message was empty, please enter a message!"
End If
If Len(mail_message) > 160 Then
MsgBox "Message is too long, please reduce by " & (Len(mail_message) - 160) & " characters.", 4112
End If
success = True
Loop Until success
If you need to repeat an action until a condition is met, check for the condition at the end of each loop. Note that the cancellation exits the Do, not the Sub.
I'm trying to output reports. They all follow the same information, just for different managers. I can't seem to get any of the right syntax in to modify the necessary parts (Recordsource, Caption, and 1 field that will contain a set string). I don't know what its asking me and I can get the code to find the next manager name (a recordsource) and cycle through them. I can get the code to output to PDF file no problem. It's the relevant code below that I need to figure out. It's probably completely wrong. I haven't really dealt with reports yet.
DoCmd.OpenReport "rptUsageReportTemplate", acViewReport
Reports("rptUsageReportTemplate").RecordSource = MngrUsgRptStr
Reports("rptUsageReportTemplate").Caption = MngrName & "'s " & Mnth & " Usage Report"
Reports("rptUsageReportTemplate").Controls("fldManagerHeader") = MngrName & "'s " & Mnth & " Usage Report"
Reports("rptUsageReportTemplate").Requery
DoCmd.Close acReport, "rptUsageReportTemplate", acSaveYes
The "docmd.openreport" Is in there because i couldn't stop getting the error 2451 - The report name [...] you entered is misspelled or refers to a report that isn't open or doesn't exist." I know it exists and I know it's spelled correctly. So it must be an open thing. If I can get Access to output reports behind the scenes without needing to see the report open and close, that would be great.
In short what I want is for the Report I saved to be a template and just update the values a bunch of times and save it to file.
Assuming that you have a "Managers" Table or similar (tblManagersOrSuch) the following untested sub should get you going...
Sub DoManagersReport(Mnth As Integer)
Dim rsManagers As DAO.Recordset
Set rsManagers = CurrentDb.OpenRecordset("tblManagersOrSuch")
If Not rsManagers.EOF Then
rsManagers.MoveFirst
Do Until rsManagers.EOF
DoCmd.OpenReport "rptUsageReportTemplate", acViewPreview, , , acHidden
Reports("rptUsageReportTemplate").Caption = rsManagers!ManagerID & "'s " & Mnth & " Usage Report"
Reports("rptUsageReportTemplate").Controls("fldManagerHeader") = rsManagers!ManagerID & "'s " & Mnth & " Usage Report"
Reports("rptUsageReportTemplate").RecordSource = "Select * from MngrUsgRptStr Where ManagerID = " & rsManagers!ManagerID
DoEvents
Reports("rptUsageReportTemplate").Visible = True
DoCmd.OutputTo acOutputReport, "rptUsageReportTemplate", acFormatPDF, "C:\" & rsManagers!ManagerID & " " & Mnth & " Usage Report.pdf"
DoEvents
DoCmd.Close acReport, "rptUsageReportTemplate"
Loop
End If
'add error handling
End Sub
Note that setting the RecordSource forces a requery so you do not require that.
I would also suggest adding a fileSaveAs function to determine the save folder...
Any ideas why I am getting an "Enter Parameter Value" input box when running this code?
Private Sub cmdPrint_Click()
Dim str As String
On Error GoTo ErrHandler
If IsNull(Me.Combo_1) Then
MsgBox "Can't print an unsaved record", _
vbOKOnly, "Error"
Exit Sub
End If
str = "Combo_1 = '" & Me!Combo_1 & "'"
Debug.Print str
DoCmd.OpenReport "rptBarCodeLabels(2)", acViewPreview, , str
Exit Sub
ErrHandler:
MsgBox Err.Number & ": " _
& Err.Description, vbOKOnly, "Error"
End Sub
Edit: The button is being used to print a label of what's currently selected in Combo_1. Once the print button has been clicked, I wanted it to display the single record I chose in the label report I have it referencing. I am using Access 2003 if that means anything.
If a field name in a query contains punctuation (Combo_1), you should enclose in brackets, like so:
str = "[Combo_1] = '" & Me!Combo_1 & "'"
The Report is expecting a parameter, but not getting it because it's not being passed through in the correct manner.
I've found a solution by using some coding that was provided here: http://www.techrepublic.com/article/how-to-print-one-or-more-labels-for-a-single-access-record/
What fixed the error was most likely creating a temporary table and temporary report.
I have a workbook which is throwing this error on opening. When it does and I open the VBA module, the current line is the definition of a sub. But the only option is to kill the whole Excel process.
I've got custom document properties, I've got embedded combo-box controls, I have no clue what it might be, and Excel isn't helping.
However, when I open the same file on another computer - it doesn't throw the error.
Does anyone have any experience or advice with this kind of error?
Here's the Open code, but the 'Show Next Statement' command doesn't point here when the error occurs:
````
Private Sub Workbook_Open()
Dim ans
If Range("currentstatus") Like "*Ready for Year-End Preparation*" Then
ans = MsgBox("This workbook is ready for Year-End Preparation" & vbCrLf & "Would you like to begin?", vbYesNo)
If ans = vbYes Then
Range("Phase") = "Year-End"
SheetsSet 3
End If
End If
'Exit Sub
If Range("Phase") = "Commissions" Then
If Range("currentstatus") Like "*RVP/Dept Head Approved*" Then
ans = MsgBox("Commissions have been approved for " & Range("applicablemonth") & vbCrLf & "Would you like to enter data for the new period?", vbYesNo + vbQuestion)
If ans = vbYes Then
Range("ApplicableMonth") = Format(DateAdd("m", 1, CVDate(Range("applicablemonth"))), "YYYY-MM")
Range("CurrentStatus") = "Ready for Data Entry for " & Range("ApplicableMonth")
' now reset the summary page
Prot False, "Commission Form Summary"
Range("SalesPersonComplete") = Range("Summary")
Range("RVPComplete") = ""
Range("BrMgrComplete") = ""
Prot True, "Commission Form Summary"
Sheets("Menu").Select
' MsgBox "Begin."
End If
End If
End If
End Sub
I had this message earlier today and it was due to another instance of Excel being open as a background process (the background process had previously opened the file in question, so it must have been something to do with that). Once I closed the other instance the problem disappeared.
It might be worth checking 'Task Manager' > 'Background processes' to see if that's the case.
This sounds like a Voodoo procedure, but what helps when I got this error is to edit any of the VBA code (for example in some module add a linebreak and remove it) and then save the workbook. Maybe it's some kind of caching issue in my case but I thought it might help some of you too.
Double-check your file extension. Excel spreadsheets with macros embedded need a *.xlsm extension, not *.xls.
Total 'for-dummies' answer, but I just made this mistake myself.