How to add a comment using comment boxes in Access? - vba

I am building an Access database for work. I have set up a report to open upon click for a certain record. So only the information of that record is to appear on the report. However, I would like to add a comment box in the report where you can add comments. The new comments are stamped and added to the previous comments already showing in the report. I was able to program the commenting function in a separate report. However, for the reports that show only specific records it won't work. I know it is because I have to somehow add each comment to my database, but I just can not figure out how to do it. I used the following code that I found online in another article. It works fine when your comments are not tied to a certain record.
Private Sub cmdAppendComment_Click()
If (IsNull(txtNewComment.Value)) Then
MsgBox ("Please enter a comment before clicking" & _
"on the Append Comment button.")
Exit Sub
End If
' These commented lines will never be reached:
' If (IsNull(txtComment.Value)) Then
' Table.tblmain.User_comment.Value = txtNewComment.Value & " ~ " & _
' VBA.DateTime.Date & " ~ " & VBA.DateTime.Time
' Else
Table.tblmain.User_comment.Value = txtComment.Value & _
vbNewLine & vbNewLine & _
txtNewComment.Value & " ~ " & _
VBA.DateTime.Date & " ~ " & VBA.DateTime.Time
' End If
' txtNewComment.Value = ""
' Use Null:
txtNewComment.Value = Null
End Sub

You would use a form, not report, for this.
Bind this to the table, add the new comment to the existing comment bound to texbox, and save the record.

Related

Cascading Combo Boxes - Dependent Box is Blank

I have a table called POHeader, which shows PO Numbers and the Vendor Number for the provider, as well as other data points for each PO.
Sometimes, we exempt a specific PO from all of our delivery rules, and I created an Access form to store these exemptions. Right now, there are two combo boxes, one for PO Number and one for Vendor Number, on the form. I want the Vendor Number combo box to filter to only vendors who match the PO Number selected by the user (PO numbers may not be unique in some cases).
Here is the VBA I wrote for the AfterUpdate event on the PO Number combo box:
Private Sub PONumber_AfterUpdate()
Me.VendorNumber.RowSource = "SELECT tblPOHeader.VendorNumber " & _
"FROM tblPOHeader " & _
"WHERE tblPOHeader.PONumber = '" & Me.PONumber & "' " & _
"ORDER BY tblPOHeader.VendorNumber"
End Sub
My issue is that the Vendor Number combo box goes blank once a PO Number is selected. What did I do wrong?
Private Sub PONumber_AfterUpdate()
Me.VendorNumber.RowSource = "SELECT tblPOHeader.VendorNumber " & _
"FROM tblPOHeader " & _
"WHERE tblPOHeader.PONumber = '" & Me.PONumber & "' " & _
"ORDER BY tblPOHeader.VendorNumber"
End Sub
I solved it!
Instead of a VBA for AfterUpdate, I updated the row source for the Vendor Number field to:
enter image description here
Then just did a requery for AfterUpdate.

VB6: Speech to Text for certain phrases

I'm creating a chatbot on Visual Basic 6.
Private Sub GreetingSub()
convo.Text = beconvo & nickname & ": " & Text.Text & vbNewLine & botname &
"Hello! How are you?" & vbNewLine
End Sub
This is a part of my code. So "nickname & ": " & Text.Text" is the user's name and what they wrote in the input box in the actual conversation box. botname & whatever is following that is what the bot replies.
I've tried Set objTextToSpeech = CreateObject("SAPI.spVoice"), however the program freezes and reads the entire conversation box, which is not what i want.
I need the chatbot to only say his reply out loud, not the user's. Any help is appreciated.

Using a saved report template and updating the Recordsource, then save to file

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...

Run-time error: The value you entered isn't valid for this field

I am trying to update a record using Subform. When I update the first time it updates properly but when I try to update the same record again I am getting the error:
Run-time error '-2147352567 (80020009)': The value you entered isn't valid for this field
The following is the form.
When I click edit, the information from the selected record is populated into the respective text-boxes. Once I update the information and click update, the record gets successfully updated for the first time.
When I try to update the same record again I get the mentioned error.
Here is the VB script that runs on clicking edit.
Private Sub cmdEdit_Click()
'Check if data exists in the list
If Not (Me.frmschoolsub.Form.Recordset.EOF And Me.frmschoolsub.Form.Recordset.BOF) Then
'get data to text box control
With Me.frmschoolsub.Form.Recordset
Me.Schooltxt = .Fields("School_Name")
Me.Desctxt = .Fields("Description")
Me.Deantxt = .Fields("Dean")
Me.Adeantxt = .Fields("Associate_Dean")
'store id of student in tag
Me.Schooltxt.Tag = .Fields("School_ID")
'change caption of button to update
Me.cmdAdd.Caption = "Update"
Me.cmdEdit.Enabled = False
End With
End If
End Sub
When I click on Debug it highlights the following line.
Me.Schooltxt = .Fields("School_Name")
Can you help me in identifying what is the issue here.
I figured that after the each update, I am losing the position of record. I added the following statement after update and Requery
Me.frmschoolsub.Form.Recordset.MoveFirst
Following is the code snippet.
Else
CurrentDb.Execute "Update School " & _
" SET School_Name ='" & Me.Schooltxt & "'" & _
", Description ='" & Me.Desctxt & "'" & _
", Dean ='" & Me.Deantxt & "'" & _
", Associate_Dean='" & Me.Adeantxt & "'" & _
"where School_ID=" & Me.Schooltxt.Tag
End If
'Clear the Fields
cmdClr_Click
'Refresh the table
frmschoolsub.Form.Requery
Me.frmschoolsub.Form.Recordset.MoveFirst
This fixed the issue.
This error is happening that a form field cannot be referenced to a textbox like you did.
You can do it as below.
With Me.frmschoolsub.Form.Recordset
Me.Schooltxt = Forms![<<if you have main form >>]![frmschoolsub].form![School_Name]

MS Project VBA getting or setting Title of custom task field Text1..Text30

I try to change the title of the task fields Text1 to Text30 in Microsoft Project 2007 using VBA.
Here is what I do manually:
In Gant Chart Task Table click on table header and add a column. In the popup I can select which task property to add, in my case “Text1” and I can enter a title, for example “my text1”.
But I don’t care about the table. I want to give the title to the text field.
I want to export Text1 to Text30 to an XML file and like to export the title of the field as well, so I need to get the title and I like to set it, because even if it isn’t used in a table it shallbe exported.
Here is what I wrote just for testing:
Private Sub setfieldtitletryout()
Dim i As Integer
Dim c As Long
For i = 1 To 30
c = FieldNameToFieldConstant("Text" & i, pjTask)
Debug.Print "Text" & i; " has constant " & c
Debug.Print " Name of Text" & i; " is " & FieldConstantToFieldName(c) ' well what a surprise...
SetFieldTitle(c, ListOfNames(i)) ' Oviously doesn't work, because the function doesn't exist :-(
Debug.Print " Title of Text" & i; " is " & FieldConstantToFieldTitle(c) ' unfortunately doen't exist too
Next
End Sub
Here is what I checked but did not ready help me…
http://msdn.microsoft.com/en-us/library/bb221504(office.12).aspx
http://msdn.microsoft.com/en-us/library/bb221254(office.12).aspx
I’d be glad to get this fixed!
Thanks in advance for helping out!
Cheers
B
Well I did it :-)
Private Sub setfieldtitletryout()
Dim i As Integer
Dim c As Long
For i = 1 To 5
c = FieldNameToFieldConstant("Text" & i, pjTask) ' get constant of custom field by name
Debug.Print i & ". Rename title of Text" & i
Debug.Print " Name of Text" & i; " is '" & FieldConstantToFieldName(c) & "'"
CustomFieldRename FieldID:=c, NewName:="Titel of Text " & i 'Rename/set custom field title
Debug.Print " Title of Text" & i; " is '" & CustomFieldGetName(c) & "'" ' get title of custom field
Next
End Sub
http://msdn.microsoft.com/en-us/library/ms453877(v=office.12).aspx
Help on CustomFieldRename
Help on CustomFieldGetName