Erasing keywords after pressing "Show All" button in MsAccess Form - forms

Please disregard, just found an answer to this:
In my MsAccess form I currently have:
Keywords window - where I can type text to look up records, by the Client Name,
Search button - after pressing on it I can see the search results
Show All button - after pressing on which I see all the records
Currently, after pressing Show All, whatever I typed in the Keywords window stays there. I wish that the keywords would be erased, every time I press Show All button
Is it possible to have such result?
If yes, what do I do or - how can I modify my Event Procedure?
Below are my event procedures codes:
btn_Search_Click() - to search by the ceratin keywords
btn_ShowAll_Click() - to show all records
Option Compare Database
Option Explicit
Private Sub btn_Search_Click()
Dim strsearch As String
Dim strText As String
strText = Me.TxtKeywords.Value
strsearch = "SELECT * from qry_Clients
where ((ClientName LIKE ""*" & strText & "*"") OR(MedRecNumber LIKE ""*" &
strText & "*""))"
Me.RecordSource = strsearch
End Sub
Private Sub btn_ShowAll_Click()
Dim strsearch As String
strsearch = "SELECT * from qry_Clients"
Me.RecordSource = strsearch
End Sub
Thank you!

Sorry, but I just found an answer!
In order to be able to clear the textbox after hitting "Show All" button,
I have to add the last string into my
Private Sub btn_ShowAll_Click():
Me.TxtKeywords = ""

Related

Macro error in SharpDevelop - is not declared

This is my first time writing a macro so I'm not sure what this error means or how to fix it. Can anyone advise me? Any help would be appreciated. I would like to say I've tried a few solutions, but as I say, this is my first time so not sure what to even try.
Public Sub DeleteUnusedViews()
'define current document
Dim currentDoc As Document = Me.Application.ActiveUIDocument.Document
'get all views
Dim viewCollector = New FilteredElementCollector(currentDoc)
viewCollector.OfCategory(BuiltInCategory.OST_Sheets)
'create list of views to delete
Dim viewsToDelete As New List(Of View)
'loop through views and check if it's on a sheet
For Each curView As View In viewCollector
'check if view is a template
If curView.IsTemplate = False Then
'check if view can be added to sheet
If Viewport.CanAddViewToSheet(currentDoc, sheetCollector.FirstElement.Id, curView.Id) = True Then
'add view to delete list
viewsToDelete.Add(curView)
End If
End If
Next
'create transaction
Dim curTrans As New Transaction(currentDoc)
curTrans.Start("Delete unused views")
'delete views in list
For Each curViewToDelete As View In viewsToDelete
currentDoc.Delete(curViewToDelete.Id)
Next
'commit changes
curTrans.Commit
curTrans.Dispose
'alert the user
TaskDialog.Show("Deleted Views", "Deleted " & viewsToDelete.Count & " views.")
End Sub
I haven't worked in VB, but in a C# macro I've had to use this.ActiveUIDocument.Document to get the active document.
Dim currentDoc As Document = this.ActiveUIDocument.Document
Perhaps 'Me' is not declared?
Also just noticed you intend to iterate through a collection of views but it looks likes your viewCollector is a collection of Elements that are ViewSheets. Where is sheetCollector defined?

Ms Access - Button with code doesn't work to send email

I have this code set in access, but no email is sending upon clicking the button on the form. I have outlook open. When i click the button on the form, i can't see anything that actually happens. I want the email address to be equal to the value in [text1], and I am trying to make the subject include a fixed message plus the input from [text2]. Even without these variables, I can't get this to work
Public Sub Command495_Click()
Dim mailto As String
Dim ccto As String
Dim bccto As String
mailto = [text1]
ccto = ""
bccto = ""
emailmsg = "trial"
mailsub = [text2] & ", Does this work?"
On Error Resume Next
DoCmd.SendObject acSendNoObjectType, , acFormattxt, mailto, ccto, bccto, mailsubj, emailmsg, True
End Sub
I have checked to make sure the onclick property shows event procedure. I am stuck, please help!
Here are a few suggestions and a modified version of your code.
ALWAYS use Option Explicit and compile your module before testing. You had a number of variables that were not defined and incorrect spelling of some options.
NEVER bypass errors when testing (get rid of your "On Error Resume Next") That's why you never saw an error.
Look for every place I entered ">>>" and address that issue.
Always explicitly define your variables and use the proper Type. Removes all doubt of what/where something is.
Option Compare Database
Option Explicit
Public Sub Command495_Click()
Dim mailto As String
Dim ccto As String
Dim bccto As String
Dim emailmsg As String
Dim mailsub As String
mailto = [Text1] ' >>> Where is [Text1]?? Remove for testing
ccto = ""
bccto = ""
emailmsg = "trial"
mailsub = [Text2] & ", Does this work?" ' >>> Where is [Text2]?? Remove for testing
' >>> Bad idea to ignore errors when testing!!
On Error Resume Next
'>>> Following line had: (1) 'acSendNoObjectType' which is incorrect; (2) mailsubj, which is undefined
DoCmd.SendObject acSendNoObject, , acFormatTXT, mailto, ccto, bccto, mailsub, emailmsg, True
End Sub

Use current form name in expression builder to create a query

I would like to refer to my current form name in the expression builder in order to create a query.
I have created the following function:
Public Function FormAtual()
Dim frm As Form
Set frm = Screen.ActiveForm
End Function
And then used it in the Expression Builder like that:
[Formulários]![FormAtual]![Lista0]
But it does not work.
Not quite sure what you are after, but to obtain the name of the active form:
Public Function FormAtual() As String
FormAtual = Screen.ActiveForm.Name
End Function
Then, to have an expression:
[Formulários](FormAtual)![Lista0]
Below is something that works with a form I am using and the steps I took. This code can be simplified, but I wanted to show how the pieces fit together.
First, create the following in a Global Module
Public Function GetVariableValue(ctlName As String) As String
Dim sFrmName As String
Dim sVal As String
' First get the Active Form Name
sFrmName = Screen.ActiveForm.Name
' Now get the value of the desired control
sVal = Forms(sFrmName).Controls(ctlName)
' Display the Form/Ctl/Value
MsgBox "Form Name: " & sFrmName & vbTab & "CtlName: " & ctlName & vbTab & "Ctl Value: " & sVal
End Function
Public Function GetFormName() As String
GetFormName = Screen.ActiveForm.Name
End Function
Next, use the query builder to select the Function and then specify the desired control. i.e.
SELECT GetVariableValue('MyID') AS Expr1, [0_Stack].Resolved, [0_Stack].WebAddress, [0_Stack].DateAdded, [0_Stack].DateChanged, [0_Stack].MyID
FROM 0_Stack
WHERE ((([0_Stack].MyID)=GetVariableValue('MyID')));

VBA Access form: Submit Button to create new record but keep some values in the form

I have a form to enter all necessary data. With the wizard I created a button that saves the data as a new record, but this button clears the form.
I want this button to do exactly that, but keep some of the entered values in the form, because those values will stay the same for a certain amount of records.
Currently my button runs this code generated by the button creation wizard:
Private Sub submit_btn_Click()
On Error GoTo submit_btn_Click_Err
On Error Resume Next
DoCmd.GoToRecord , "", acNewRec
If (MacroError <> 0) Then
Beep
MsgBox MacroError.Description, vbOKOnly, ""
End If
submit_btn_Click_Exit:
Exit Sub
submit_btn_Click_Err:
MsgBox Error$
Resume submit_btn_Click_Exit
End Sub
When the button is clicked I want to clear all values in the form, except for the date and a group field. Can I easily do this in this code or is there a way to do this via the default value property of these fields?
Try the following:
Go to the properties of your form and put the following code in the BeforeUpdate event:
Private Sub Form_BeforeUpdate(Cancel As Integer)
entry_date.Tag = CLng(entry_date.Value)
acc_value.Tag = acc_value.Value
End Sub
In the Current event of the form, put the following code:
Private Sub Form_Current()
If Me.NewRecord Then
entry_date = CDate(entry_date.Tag)
acc_value = acc_value.Tag
End If
End Sub
That is all you need to do. If you have any questions please let me know

Access VBA visible control form from another form

I have a table and form setup to control another form in my database.
I'm wanting to make a code that will take the title from my field and add it to my code as a variable to change the visibility options of my other form.
my form is set with all the of the names to all objects on the form I want to control.
LSE_FORM_ADMIN = The table with all the LSE_FORM_ALL names in it.
Table is setup with 3 columns key, names and a checkbox which I put into a form to make a continuous list.
here is my code on the form, but I keep getting and runtime 424: object required error:
Private Sub Form_Current()
Dim VARSET As Object
Dim VAR As String
VARSET = DLookup("TITLE", Table!LSE_FORM_ADMIN, "") 'keep getting error here
VAR = VARSET
If Me!CB = "-1" Then
Form_LSE_FORM_ALL!VAR.Visible = True
Else
Form_LSE_FORM_ALL!VAR.Visible = False
End If
End Sub
can someone help me fix this code so that it will grab the title field data and make it a variable to add to the rest of the code?
It's difficult to see exactly what you are trying to achieve, but your problems stem from using the variant variable type when you should be using an explicit Form or Control type. Using your last example.
RSTT.Visible = True 'getting Run-time error '424': object required
This is because you have declared RSTT as a variant. The line
RSTT = "Form_LSE_FORM_ALL" & "!" & (RST)
results in the variable RSTT containing a string, which does not have a property ".Visible"
Set DB = CurrentDb
Set RS = DB.OpenRecordset("LSE_FORM_ADMIN")
These lines are redundant as you have the values that you need available on the form fields which are already bound to the table LSE_FORM_ADMIN.
As far as I understand, you have a continuous form (ADMIN?) bound to the table LSE_FORM_Admin. As you step through the records on this form, you want code to be fired which takes the value of the TITLE field/control and use it to set a control with the same name, on a separate form, Form_LSE_FORM_ALL, to be (in)visible, dependent on the value of the checkbox control name CB on the ADMIN form?
If you want the ADMIN form to make the changes "live" to the ALL form, you should consider using an event of the CB checkbox control. Using the current event of the form means that the changes you make will not be reflected in the ALL form until you step out of the record you have just edited, then back in, to fire the form's Current event on that record.
Example using AfterUpdate event of CB checkbox
Private Sub CB_AfterUpdate()
Dim strRST As String
Dim frmTarget as Form
Dim ctlRSTT As Control
Set strRST = Me!TITLE
Set frmTarget = Forms("Form_LSE_FORM_ALL")
Set ctlRSTT = frmTarget.Controls(strRST)
ctlRSTT.Visible = Me!CB 'getting Run-time error '424': object required
End Sub
really not sure how to do the syntax when doing a recordset to a table from the form, need some help with that.
here is my code and attempt at the record set:
Private Sub Form_Current()
Dim DB As Database
Dim RS As Recordset
Dim RST As String
Set DB = CurrentDb
Set RS = DB.OpenRecordset("LSE_FORM_ADMIN")
Set RST = RS 'GETTING OBJECT REQUIRED ERROR ON "RST ="
Do Until RS.EOF
RST = Me!TITLE
RS.MoveNext
Loop
If Me!CB = "-1" Then
Form_LSE_FORM_ALL!RS.Visible = True
Else
Form_LSE_FORM_ALL!RS.Visible = False
End If
End Sub
I think I know what you are trying to do, but your descriptions / references are not matching up. Please look at the following comments and clarify:
1. You say "...make a code that will take the title from my field and ..." but your code is taking "Me.Title", "ME" is a reference to the Form - not a field.
2. Your code is in the "Form_Current" event, which means it will fire for every record you process. That will work, but I think you want to do this code only once to be more efficient.
3. You have no provision for processing more than one field. I think you need to loop through all fields in your table, setting visible to true or false.
The following is my suggestion, but I will update once you clarify the issues.
Option Compare Database
Option Explicit
Dim DB As DAO.Database
Dim RS As DAO.Recordset
'Dim RST As Variant
'Dim RSTT As Variant
Public Sub FORM_CURRENT()
Set DB = CurrentDb
Set RS = DB.OpenRecordset("LSE_FORM_ADMIN")
Do While Not RS.EOF ' Loop thru all field names for the form
If RS!HideYN = True Then ' Desire to hide the field?
Me(RS!ctlname).Visible = False ' Yes, hide the field.
Else
Me(RS!ctlname).Visible = True ' No, show the field
End If
RS.MoveNext ' Get next field name
Loop
RS.Close
Set RS = Nothing
Set DB = Nothing
'Set RST = Me!Title
'RSTT = "Form_LSE_FORM_ALL" & "!" & (RST)
'If Me!CB = "-1" Then
' RSTT.Visible = True 'getting Run-time error '424': object required
'Else
' RSTT.Visible = False
'End If
End Sub
Final code, thanks to Cheesenbranston.
Private Sub Form_AfterUpdate()
Dim strRST As String
Dim frmTarget As Form
Dim ctlRSTT As Control
strRST = Me!TITLE
Set frmTarget = Forms("LSE_FORM_ALL")
Set ctlRSTT = frmTarget.Controls(strRST)
If Me!CB = "-1" Then
ctlRSTT.Visible = True
Else
ctlRSTT.Visible = False
End If
End Sub
#Cheesenbranston: Your original code was more like a toggle of on and off so if my object was not visible then my trigger checkbox would make it visible when checked, more of a quality of life for my own needs, none the less worked. Also strRST doesn't need SET since its just a String. Thanks again =D very happy day!