Access Search Subform + Update Query Subform? - forms

So I'm new to Access 365, and I'm working on a database for my church's cemetery. I have a "main" form that will house searches and the results of said searches (https://i.imgur.com/v6ZmDx2.png).
So I'd like to put a box on this form that when I press the "Run Query" button, updates with all records matching the criteria. I have the query working, and if I go into the individual search form and search, it works fine.
If I try dragging the query onto the main form, I get a SearchQuery subform, but when I go into form view, I have to fill out data before the form even loads. I need it to only update after I click the button, so that I can enter info, THEN search (https://i.imgur.com/6jJ416o.png & https://i.imgur.com/XPPpg6S.png). If I click cancel, it loads fine, but when I type in data to the search then press "Run Query", it still prompts me for the info (https://i.imgur.com/FKbZ6WK.png).
Thanks in advance!

Your code is constructing criteria with control names as the data to search in, must use table field names. Remove the Result_ from each expression.
Coffin and Cremation radio buttons are within an OptionGroup control. This means you must test for the value of the OptionGroup, not the controls within the group. Clicking radio button sets value of the OptionGroup control. Following is revised code for the OptionGroup and checkboxes. Note removal of Result_ - fix the other conditional expressions as well. Might want to rename the OptionGroup control.
'Coffin/Cremation
If Not IsNull(Me.optGroup) Then strFilter = strFilter & "([Coffin/Cremation] = " & Me.optGroup & ") AND "
'Veteran
If Not IsNull(Me.Veteran) Then strFilter = strFilter & "([Veteran] = " & Me.Veteran & ") AND "
'Monument
If Not IsNull(Me.Monument) Then strFilter = strFilter & "([Monument] = " & Me.Monument & ") AND "
Why is the Clear Search button using EmbeddedMacro? Code to clear search parameters:
Private Sub cmdReset_Click()
'Purpose: Clear all the search boxes in the Form Header, and show all records again.
Dim ctl As Control
'Clear all the controls in the Form Header section.
For Each ctl In Me.Section(acHeader).Controls
Select Case ctl.ControlType
Case acTextBox, acComboBox, acCheckBox, acOptionGroup
ctl.Value = Null
End Select
Next
'Remove the form's filter.
Me.FilterOn = False
End Sub
Consider using comboboxes instead of textboxes to help users enter valid data. Can still allow any input and use LIKE/wildcard. RowSource SQL could be like:
SELECT DISTINCT [Last Name] FROM A ORDER BY [Last Name];
Advise not to use space nor punctuation/special characters (only exception is underscore) in naming convention.

You can access any form from the subform as follows:
MainForm: LOAN SETTLEMENT FORM
ex:
Forms![LOAN SETTLEMENT FORM]!txtEMP_ID.Value = Me.EMP_ID.Value
Forms![LOAN SETTLEMENT FORM]!txtEMP_NAME.Value = Me.EMP_NAME.Value

Related

Open Form to a value selected on ComboBox - Ms Acces

I want to open a form to a specific record based on the value is selected on a comboBox. I have written a code and its working, but before opening the form it shows a dialogue box with input field asking for the parameter i want for the form which i dont want the VB code to ask.
DoCmd.OpenForm "Final_Exam", acNormal, , "[admclass] = " & Me.Combo4.Value & ""
This is the code i have written and the requirement is that on clicking the button the form opens without any dialogue box asking for parameter. thanksa
What I've found is the best way to open one form from another is to use OpenArgs. When opening Form 2 from Form 1's button, use code like this:
Private Sub cmdOpenOtherForm_Click()
DoCmd.OpenForm FormName:="frmOtherForm", OpenArgs:=Me.Combo4.Value
End Sub
Then, in the Load event of Form 2, use the openargs to set up your filter:
Private Sub Form_Load()
If Not IsNull(Me.OpenArgs) Then
Me.Filter="[admclass]=""" & Me.OpenArgs & """"
Me.FilterOn = True
End If
End Sub
If the field you're filtering on is a text field, make sure to properly escape double quotes (as is done above).

Crosschecking account number between two access tables when using forms

I am using a form to enter new data into the table: tblMonthlySummary. I am entering Account Number, Currency, and Closing Local Balance.
When I enter the account number into table tblMonthlySummary, I would like Access, either through a macro or VBA, to crosscheck the table tblStaticBankDetails for the account number that would be added to tblMonthlySummary.
If the account number does not exist in tblStaticBankDetails, I would like VBA or a macro to return a Windows dialog box that says, "Invalid account number".
Here is the current code I have in VBA for my Add Entry to Table Button, Clear Fields, and Close Form. These buttons are on a form labeled: frmMonthlyManualUpdate.
Add Data Code
Private Sub cmdAdd_Click()
'add data to table
CurrentDb.Execute "INSERT INTO tblMonthlySummary([Account Number], [Currency], [Closing Balance]) " & _
" VALUES('" & Me.txtAccountNumber & "','" & Me.cboGender2 & "', '" & Me.txtClosingBalance & "')"
'clear form
cmdClear_Click
'refresh data in list on form
frmMonthlySummarySub.Form.Requery
'confirmation of end
MsgBox "Account number and balance successfully recorded."
End Sub
Me.cbogender2 is my currency blank.
Clear Fields Code
Private Sub cmdClear_Click()
Me.txtAccountNumber = ""
Me.cboGender2 = ""
Me.txtClosingBalance = ""
'focus on TxtAccountNumber
Me.txtAccountNumber.SetFocus
End Sub
Close Form Code
Private Sub cmdClose_Click()
DoCmd.Close
End Sub
Using a combo box is the way to go.
You can set it's properties to only allow values that are on it's list to be entered into the field. Users can either choose a value from it's list OR type the account manually. It won't let a value be entered that is not on the list.
How many accounts might have their summary row missing?
If it's only a small number you might want to consider:
Using SQL to insert the account numbers that are not in tblMonthlySummary that are in tblStaticBankDetails.
Then the user can see which ones are missing and find out what the values should be. (ie filter to form to view account with missing details)
It is strange that you are using a button to execute and insert statement. It is more common for an Access form to be based on an updatable record source (like you list) and for the user to simply click the "new record" button to insert a row.
PS. I would expect referential integrity to be set up between these two tables to stop any incorrect values being entered for account number as well.
Harvey

Update Access Tables with Data entered in forms

I have created a form to search for a record based on user input. user searches for a Site using SiteID which he enters and clicks okay. Which opens up another form with all the details for the site. User can then make changes to the Site details in this form and when he presses enter button it should update the table with all the changes made. Changes could be one text box or several text boxes.
I wrote a query but it is throwing error:
Private Sub Enter_Click()
SQL = "UPDATE Tracker " _
& " SET Tracker.[Site ID] = " & Me.[Site ID] _
& " , Tracker.[EHR Vendor] = " & Me.[EHR Vendor] _
& " , Tracker.[Site Name] = " & Me.[Site Name] _
& " WHERE Tracker.[Site ID] = " & Me.[Site ID] & ";"
DoCmd.RunSQL SQL
End Sub
Is this the best way to proceed or is there another method I can follow.
I would create a form, let’s call it subtracker, that contains all of the fields in the tracker table. Then in design view of the form where the user selects the siteID I add the subtracker form as a sub form and link the siteID field on the sub form to the selection box on the main form. Adding a sub form is an option on the design tab

Access, Opening the Same Form in Different ways using Buttons

I'm using Access 2007 at work and trying to build a database. I'd like to know if it's possible to have two different buttons on the "Main Menu" form that open the same "Data Entry" form. BUT, one button automatically goes to a new blank record for data entry, and the other button prompts the user to enter a specific ID # (tied to a field in the form) and then the form will open on that record. This would be for updating that specific record.
Is this possible? I am a beginner with VBA code. If this is possible with later versions of Access but not 2007, please let me know.
Create two buttons on the form. Let us name them as addRecBtn and openRecBtn let us say the form you are trying to open is tmpFrmName. So the first button will open the form in Data Entry Mode, the second one will open the form in normal edit mode.
The code should be something like,
Private Sub addRecBtn_Click()
DoCmd.OpenForm "tmpFrmName", DataMode:=acFormAdd
End Sub
The second form will first have to get the number you are trying to open, for example let us call it the numberID. So your code would be.
Private Sub openRecBtn_Click()
Dim numID As Long
numID = InputBox("Please enter the ID : ")
If DCount("*", "yourTable", "numberID = " & numID) <> 0 Then
DoCmd.OpenForm "tmpFrmName", WhereCondition:="numberID = " & numID
Else
MsgBox "The numberID : " & numID & " does not exist, please try again !"
End If
End Sub
You may be able to use DoCmd.OpenForm with different options to accomplish both your goals.
"one button automatically goes to a new blank record for data entry"
DoCmd.OpenForm FormName:="YourForm", View:=acNormal, DataMode:=acFormAdd
"the other button prompts the user to enter a specific ID # (tied to a field in the form) and then the form will open on that record"
Dim strWhere As String
strWhere = "[id]=" & Me.txtId
Debug.Print strWhere ' <- inspect this in the Immediate window
DoCmd.OpenForm FormName:="YourForm", View:=acNormal, WhereCondition=strWhere
The first form includes a text box named txtId, which contains the ID value you want to make current in the second form (YourForm).
Yes, it's possible.
My advice would be to do it with several functions - put the "shared" functionality in one (eg open the form), and then for the differences, make two functions which call the shared one
eg
function openForm()
{
//Do open form stuff
}
function promptForID()
{
openForm();
//Do stuff that prompts for ID
}
function blankRecord()
{
openForm();
//Do stuff that sets up a blank record
}

Cannot view records in form ms access after assigning record-source

Please help,
I have this table ‘Source_RM’:
Source.........Raw Material.....Waste Date.....Waste Quantity
Store.............Sugar...........13/06/2013.................10
Store.............Salt...............12/06/2013.................13
Production....Sugar............17/06/2013.................10
Vendor..........Sugar............15/06/2013.................10
I have a main form where the client can perform queries passed on controls (text box, combo box ..)
In the main form I need to display a query result passed on combo box value:
The result wanted: the client choose the source from a combo box "cmbSource" so the result will be a table contain the source and total waste i.e.:
Source...Total
Store.......23
What I did is:
Created a form (“Blank Form”) name it: frmResult
In the main form I added Subform, In subform wizard in use an existing form I chose ‘frmResult’
After I choose the source from ‘cmbSource ‘ and click the button’ cmdFilter’
I wrote this code in VBA :
Private Sub cmdFilter_Click()
Me.FormTemp.Form.RecordSource = "SELECT Source_ID, SUM(Quantity) AS Total FROM Source_RM WHERE Source = ' " & Me. cmbSource.Value & " ' GROUP BY Source_ID;"
End Sub
After I click the button, the FormTemp has the RecordSource (I know from the record number at the bottom bar’ 1 of 1’) but the FormTemp still blank .. I need to show the result of query in FormTemp
Note : Date entry in FormTemp is set to NO.
I put the default view of FormTemp to Datasheet.
Please any Ideas
Thank you