Access 2013: Send the form's current record only to a PDF using a report - ms-access-2013

I have a form where users input all of their data. There is a 'Save' button which saves the record, and leaves the form up and active.
Before I close the form, I need to take that newly saved record and output the associated report to a PDF file.
My problem right now is that the output to the PFD is sending all records in the table, not just the record in the form.
Here is my code at this point.
Private Sub cmdSave_Click()
Dim outl As Outlook.Application
Dim mi As Outlook.MailItem
Dim strWhere As String
Cause = "SaveButton"
DoCmd.RunCommand acCmdSaveRecord
'Save the Record
Me.btnClose.SetFocus
If Me.DateOfVisit <> "" Then
Me.RepStatus = "Report Saved!"
Me.btnNewReport.Visible = True
'Now, print the report to a PDF File
DoCmd.OutputTo acOutputReport, "rptReports", acFormatPDF,"C:\ReportTest.pdf", False
End If
End Sub
As a side note, it is required that the users would not see a report pop up on the screen and then quickly disappear.
Thanks for any assistance.

Looks like I finally noodled it out.
I added the following lines and now it is working.
Turns out that the OutputTo has no way to pass in any search criteria.
So, I opened the report in Hidden mode so the users don't see anything and then use the OutputTo to send it to a PDF.
'Now, print the report to a PDF File
DoCmd.OpenReport "rptReports", acViewReport, , "[ReportID] = " & [ReportID], acHidden
DoCmd.OutputTo acOutputReport, "rptReports", acFormatPDF, "C:\TG QUOTE SYSTEM\Meeting Reports\ReportTest.pdf", False
DoCmd.Close acReport, "rptReports"
End If
Thanks all.

Related

Is there any way to save the checkbox's state of a program made in visual basic 6.0

I have made(designed) a program in Visual Basic 6.0,it consists of around 100 checkboxes ,the program does not require any code just a yes/no checkbox type program , but I want to save the checkbox state ,so that if a check box is in yes state then after restarting the program it's state remains conserved .
I have read about
My.Settings.Save but I dont know how to use it , I am using Visual Basic 6.0.
Create keys in Registry, save each checkbox value on their checkbox Change event and load the status of each of them in the form Initialize event code.
Option Explicit
Private Const MyApp As String = "My Own App" 'put here your application name
Private Const Sett As String = "Settings"
Private Sub CheckBox1_Change()
Dim chkBoxStatus As String
chkBoxStatus = "CheckBox1"
If Me.CheckBox1.value = True Then
SaveSetting MyApp, Sett, chkBoxStatus, CStr(True)
Else
SaveSetting MyApp, Sett, chkBoxStatus, CStr(False)
End If
End Sub
Do the same for all your check boxes.
And then:
Private Sub UserForm_Initialize() 'I do not remember well if VB6 uses Form_Initialize... You must adapt it accordingly.
Dim regValue As String
regValue = GetSetting(MyApp, Sett, "CheckBox1", "No value")
If regValue <> "No value" Then Me.CheckBox1.value = CBool(regValue)
'do the same for all checkboxes in discussion
'.
'.
End Sub
"No value" is returned if no value has been set in Registry (yet)...
Well, I would have made all checkboxes a control array and would save their sate in a text file in some hidden place, like C:\Users\UserName\AppData\Local. It would be a pretty small code.

How do I add a save feature to a datagridview?

Hi i am fairly new to visual studio and I am having some trouble adding a save feature to my program. Basically what my program does is set event reminder for the user (it's like a daily planner but with no notifications). I have got the "add event', "delete", and "update buttons to work on the program and now all I have left is the "save" and "load" key. What I am trying to do is find a way to save the DataGridView so it can be opened back up in the program at a later date using the "load" key. If it would be easier to just remove the "load" and save the info right into the event reminder application, I could go that route but I don't have the first idea how to do that. This is what I have right now for the code in the main form:
Public Class MainForm1
Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
If DataGridView1.Columns(e.ColumnIndex).Name = "Delete" AndAlso Me.DataGridView1.Rows(e.RowIndex).IsNewRow = False Then
Me.DataGridView1.EndEdit()
Me.DataGridView1.Rows.RemoveAt(e.RowIndex)
End If
If DataGridView1.Columns(e.ColumnIndex).Name = "Column4" AndAlso Me.DataGridView1.Rows(e.RowIndex).IsNewRow = False Then
Dim Update As UpdateWindow
Update = UpdateWindow
Update.Show()
End If
End Sub
Private Sub dltBtn_Click(sender As Object, e As EventArgs)
Dim dltBtn As dltWindow
dltBtn = dltWindow
dltBtn.Show()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim Button1 As addBtn
Button1 = addBtn
Button1.Show()
End Sub
Private Sub UptBtn_Click(sender As Object, e As EventArgs)
Dim UptBtn As UpdateWindow
UptBtn = UpdateWindow
UptBtn.Show()
End Sub
Dim thisFilename As String = Application.StartupPath & "\Event reminder.dat"
Private Sub saveBtn_Click(sender As Object, e As EventArgs) Handles saveBtn.Click
Me.Validate()
Me.SaveGridData(DataGridView1, thisFilename)
End Sub
Private Sub BtnLoad_Click(sender As Object, e As EventArgs) Handles BtnLoad.Click
Me.LoadGridData(DataGridView1, thisFilename)
End Sub
Private Sub SaveGridData(ByRef ThisGrid As DataGridView, ByVal thisFilename As String)
ThisGrid.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithoutHeaderText
ThisGrid.SelectAll()
IO.File.WriteAllText(thisFilename, ThisGrid.GetClipboardContent().GetText.TrimEnd)
ThisGrid.ClearSelection()
End Sub
Private Sub LoadGridData(ByRef ThisGrid As DataGridView, ByVal Filename As String)
ThisGrid.Rows.Clear()
For Each THisLine In My.Computer.FileSystem.ReadAllText(Filename).Split(Environment.NewLine)
ThisGrid.Rows.Add(Split(THisLine, " "))
Next
End Sub
End Class
I have gone on the other forums and asked about how to do this and they all said the bind the datagridview to a data table. If that is the route I have to go, how do I go about it? If anyone has some examples or code I could try out I would be much appreciative.
The problem I can see in the posted code is between the LoadGridData and the SaveGridData methods. When the LoadGridData method runs, it reads a file where each line is “Split” on spaces “ “. This is fine and if the file is properly “space” delimited it works as expected. So let us assume everything works and the data displays in the grid properly.
Then the user presses the saveBtn which calls the SaveGridData method. The code appears to “select” all the cells in the DataGridView to the clipboard, then proceeds to write the clipboard text to the SAME file name used when loading the grid. This also appears to work as expected.
The problem with this is that when the code copies all the cells of the DataGridView to the clipboard then, writes this copied clipboard text; it will use a “Tab” delimiter. The file Event reminder.dat which was read in using a “space” delimiter will be overwritten with a “tab” delimiter and not a “space” delimiter. Therefore, then next time the load method is run… it will fail.
If the load and save button are going to read the same file, then they MUST both agree on what character is used as a delimiter. You can use whatever character you want as a delimiter. You can use a “space” as the posted code does, however this limits each type to a string with no spaces. If one of the fields is a home address, chances are good, there will be a space in the string. Using a “space” as a delimiter is not necessarily the best of choices.
A simple solution is available with the current code. Currently if the file Events reminder.dat is space delimited and reads in properly to the data grid view, then it should be easy to replace the space delimiter with something else. In this case, since the SaveGridData method is delimiting the fields with a “tab” then we simply need to change the load method to “split” on “Tabs” and not “spaces” when reading back the file.
Step 1 – make a copy of Events reminder.dat
Step 2 – Run the program, press the load button and make sure all the data is properly loaded into the grid.
Step 3 – If the data is displayed properly in the grid, press the save button. (Updates file with tab delimiters)
Step 4 – Exit the program and make the change below in the LoadGridData method.
ThisGrid.Rows.Add(Split(THisLine, vbTab))
Step 5 – Run the program. Now both the load and write methods agree on what character (Tab) is used as a delimiter.
Lastly, to comment on using a DataTable the answer would be yes. DatagridViews and DataTables play nicely together. Hope this helps.
You may want to take a “Tour” of Stackoverflow to see how it works.

how to send contents of a textbox in vb6 to a notepad document

I am trying to send the data inserted into a textbox into a notepad document so that the data can be held for future reference, as i am trying to create an assessment date reminder as i am a student.
But whenever i try to send the data with this code by writing data = "txtAssign_Name, txtAssign_Due" when i check the notepad after running the program, all that is in the document is txtAssign_Name, txtAssign_Due.
Private Sub Form_Load()
Dim Data As String
txtAssign_Name.Text = ""
txtAssign_Due.Text = ""
Data = ""
Open "F:\Personal\date calender test - Copy\test.txt" For Output As #1
Print #1, Data
Close #1
End Sub
Try this:
Data = txtAssign_Name.Text & ", " & txtAssign_Due.Text
(In the lines above, you will want to NOT set those values to "")
Note - using the built in VB6 writing to text files will result in your output being formated in a way so that VB6 can read it back in again. So all strings will have quotes aroud them, other values are displayed in a variety of odd ways, commas seperate all values.
If the output text file is desired to be primarily for human use, then I find using the richtextbox control a better way of creating the file. Add it from Project -> Components -> Controls -> Microsoft Rich Textbox Control 6.0
Add the Rich text box to your form (you can set visible = false if you don't want users to see it). Add your data to it something like this:
RichTextBox1.text = txtAssingn_Name.text & ", " & txt_Assing_Due.text
' If you need to add more things, add them on to the end like this
RichTextBox1.text = richtextbox1.text & vbcrlf & "More text on the next line"
Then, when all the data is added, you just do this
RichTextBox1.SaveFile "C:\Test.txt", rtfText
rtfText is a visual basic constant, that tells the RTB to save as plain text. The alterntaive is rtfRTF. You can learn more about the RTB on MSDN
OK, so a comment above states that you want to be able to read the data back into VB.
The code as it shown in the question will just output a blank text file, as the variable Data is set to "", so that is all that will be output.
What you need is something like this
private Sub SaveData()
dim SaveFile as integer
SaveFile = Freefile ' This gets a file number not currently in use
Open "F:\Personal\date calender test - Copy\test.txt" For Output As #Savefile
write #SaveFile, txtAssign_Name.Text, txtAssign_Due.Text
close #savefile
end sub
And call SaveData in the appropriate place. NOT form load, as the user won't have entered anything at this point. Either after the user has pressed a button, or on Form_Unload if you want it to autosave on form close.
To populate your form again, something like this
private sub LoadData()
dim LoadFile as integer
dim StringData as string
loadfile = freefile
Open "F:\Personal\date calender test - Copy\test.txt" For Input As #loadfile
input #loadfile, StringData
txtAssign_Name.Text = StringData
input #loadfile, StringData
txtAssign_Name.Text = stringdata
close #loadfile
end sub
You should also add error handing whenever working with files. VB6 is quite particular and its very easy to throw an exception when dealing with files.

Web Page not updated when value is selected from web list using QTP

So I have been searching for an answer for this for a long time, and have come up with a temporary solution which i'll write below, but I was wondering if theres a more elegant one?
In the application im working on there is a weblist which can contain one of four values which are: 10,25,50,100. When a value is selected the web table below should show 10,25,50 or 100 results depending on the value selected of course.
Now when I call the standard Obj.Select "100" for example it changes the list box to 100 but nothing else happens. No event is triggered so the web table below remains the same. If I manually select 100 the web table updates to display 100 records.
I tried firing different events to the web list but none of them seemed to update the web table!
In the end I settled on the solution below:
Public Function CustomSelect(obj, strValue)
Dim intCounter, strProperty, boolItemInList, strEnabledOrDisabled, arrAllItems, strAllItems
Dim xCoord, yCoord
If strValue = "##" Then
Call AddComment("Passed in ##, skipping set function")
Exit Function
End If
Reporter.Filter = rfEnableErrorsOnly
strProperty= obj.GetTOProperty("name")
If strProperty= "" Then
strProperty= obj.GetTOProperty("html id")
End If
Reporter.Filter = rfEnableAll
If obj.exist(5) Then
XCoord = obj.GetROProperty("abs_x")
YCoord = obj.GetROProperty("abs_y")
strEnabledOrDisabled = obj.GetROProperty("disabled")
If strEnabledOrDisabled = 0 Or strEnabledOrDisabled = "0" Then
strAllItems = obj.GetROProperty("all items")
arrAllItems = split(strAllItems,";")
For intCounter = LBound(arrAllItems) to Ubound(arrAllItems)
'Obj.SendKeys "{DOWN}"
Obj.Select "#" & intCounter
If arrAllItems(intCounter) = strValue Then
Exit For
End If
Next
Else
Call ReportExpectedVsActual("Weblist is disabled: " & strProperty, False, True)
End If
Else
Call ReportExpectedVsActual("Weblist doesnt exist: " & strProperty, True, False)
End If
End Function
RegisterUserFunc "WebList", "CustomSelect", "CustomSelect"
I know it looks a bit messy but its all I can think of to get it working at the moment. Does anyone have any other ideas of what to try?
Cheers
Nick
There are at least two things to try:
Try to look into the source of the webpage to see how an action is triggered. It could be something like onchange='RefreshIt();' or you'll see an EventHandler attached to it, then you have to dig somewhat deeper.
If you have indentified the event that will update your page, try firing that event after updating the list with WebListObject.FireEvent {yourEvent}. yourEvent could be a string containing onchange, onclick, ondblclick, onblur, onfocus, onmousedown, onmouseup, onmouseover, onmouseout, onsubmit, onreset or onpropertychange.
Another way that is even simpler (but giving you less control) is worth a try. This is done through the settings: Go to Tools > Options and in the tree view, select Web > Advanced. Try what happens when changing the checkbox for Run only click and the radiobuttons for Replay type.

Unable to save Excel file after modification using Ruby & win32ole

Using http://ruby-doc.org/stdlib/libdoc/win32ole/rdoc/classes/WIN32OLE.html as a guide I have written the following:
require 'win32ole'
excel = WIN32OLE.new('Excel.Application')
excel.visible = false #Setting this is 'true' doesn't reveal anything
workbook = excel.workbooks.open('C:\myspreadsheet.xlsx')
worksheet = workbook.worksheets('sheet1')
worksheet.Activate
data = worksheet.UsedRange.Value
p data.size #This works! - My spreadsheet has 3987 rows.
p data[3932] #This works, too! - I can "see" row 3932.
worksheet.Rows(3932).Insert #Insert a row above row 3932
data = worksheet.UsedRange.Value
p data.size #Returns 3988! This would seem to indicate that I've successfully added a row since it was just 3987.
workbook.saved = true #Save the workbook and quit.
excel.ActiveWorkbook.Close(0)
excel.Quit()
When I open the Excel spreadsheet after all of this it is unchanged. Any ideas?
Setting the Saved property of a Workbook object to True does not cause the workbook to be saved. That property is used as a flag to show whether a workbook has unsaved changes. Setting it to True is a simple way of preventing the "Do you wish to save..." dialog appearing when Excel is closed.
To actually save the workbook, you need the Save method of the Workbook object. This method doesn't return anything so I would assume that workbook.Save would do the trick (I have no experience of Ruby, unfortunately, so can't be 100% sure on that)

Resources