Opening form from combo box in another form - ms-access

I have a form called DisplayForm. In that form is a combo box drop down that is at the top of column on the form where a label would usually go. I want to select an item from that drop down menu and use that bit of data to open another form. I have copied an example from the web, changed the names and can't get it to work. Here is the code;
If Not Me.NewRecord Then
DoCmd.OpenForm "AreaForm", _
WhereCondition:="LArea=" & Me.AreaCBDrop
End If
Area is the name of the field in the query that is the recordsource for the form, but when I run it, it opens a msgbox that wants me to enter a peramater value. I also don't understand what the IF is about. I have tried this with and without the if but get the same result. Me.AreaCBDrop has the correct value in it, but the where does not work.
Thanks
Thanks

Your WHERE condition is expecting a text parameter, but you are not supplying the expected format, so it is asking for one.
Surround your Me.AreaCBDrop with single quotes, like this:
If Not Me.NewRecord Then
DoCmd.OpenForm "AreaForm", _
WhereCondition:="LArea='" & Me.AreaCBDrop & "'"
End If

Related

How to pass value from subform to mainform ms access

I have a form with a subform (Datasheet view form). When i click a row in subform, i want pass that row value to text box in main form . In subform even wrote this
Private Sub Form_Click()
MsgBox (Noloan)
End Sub
But i don't know how to pass that subform form_click no_loan to mainform.textbox. Thanks for your help.
Additional data:In my db , i have a table which consist field No,NoLoan,Name. NoLoan Field value as i wanna clicked .From that table i create a subform/datasheet view ,subform name is T_Loan1. Then I create Main Form, name is FindLoan2. In that main/parent form i create text box, called Text7, and put T_Loan1 in subform object at footer.
I put this
=[Forms]![FindLoan2]![subformTLOAN].[Form]![Noloan]
in my Text7 Control and It's work.
Thank's for all attention.
Goto to the subform and click on the field which has the row value
Select Field property - click on events tab --> On Click --> Code Builder
Put below code in the Click event where Form_frmMain is your form name and Me.ID is the field.
Private Sub ID_Click()
Forms!FindLoan2.Text7 = Me.ID
End Sub
The best way is to write code that ignores the forms!names. If you copy the form, or change the sub form, or even drop the sub form into a different form, then all your code breaks.
To reference the textbox in the parent form from code, use:
me.Parent!Text7 = me!id
I am not sure which version of MS Access you are using, but it is also possible to use Tempvars to store values for use elsewhere if you have a complicated application which makes referencing another form/field/control difficult.
To create:
Tempvars.Add "TempVarName", TempvarValue
To use:
Tempvars!TempVarName
To remove:
Tempvars.Remove "TempVarName
I try to limit my use of them, as it becomes hard to manage. I am always careful about when I set the values and I ensure that they are removed after I am finished with them to avoid confusion or issues with values persisting when they shouldn't.

How do I make a search form in Access 365

I am currently trying to make a search form for my database. I want to place it in a navigation form (so I heard I can't use a split form). I currently have a form with 4 text boxes and one combo box for a total of 5 criteria to search with a separate button for each. Underneath, is a query based on my table. This is what I have done so far
I'm hitting a wall on how to actually perform the search though. I have never used access before this project and have no idea how to use VBA (but I do know other languages). Is it possible to perform the search using macros? If not, how would I make a search sub-procedure?
The way you approach this is to build the search form and develop and test the search form. Get it working? You can then drop this working form into an existing “navigation form set”.
There are a gazillion ways to do this – you are quite much only limited by your imagining. However, a common setup is to create a “main” form. This main form can have a few text boxes for you to type in your search values. And then you use the wizards to create a “results” form (a nice form in which you display the results for the user to see + pick the results).
In fact, you really don’t have to use a form + sub form, but I find this often works somewhat better then placing the “criteria” boxes in the forms heading area.
So create main form – this form is unbound (not attached to any table in the system). Have fun, lay out the form anyway you want.
Then use the wizards to create a multiple items form. Get that form laid out with nice columns. Now with main form in design mode, simply drag + drop in the “display results” form.
The result is an access form that looks like this:
In above, note how the user “typed” in some criteria.
So you place some code in the text box “after” update event. It can look like this:
dim strSql as string
strSql = "select * from tblCustomer where LastName like " & me.txtLastName
& "*"
me.MySubFormname.Form.RecordSource = strSql
So we “build” the sql on the fly, and “stuff” the sql right into the sub form to display the results.
Note also in the above contines items form, we have a “view” or “edit” button when clicked can launch a detail form to the ONE record you select. In my example I used a “glasses” icon for the button. The code behind that buttion is thus:
Docmd.OpenForm "frmEditDetails",,,"id = " & me!id
edit: the sql string has to be correct, so in above, it should be:
dim strSql as string
strSql = "select * from tblCustomer where LastName like '" & me.txtLastName & "*'"
debug.print strSql
me.MySubFormname.Form.RecordSource = strSql
So VERY little code is required. The rest is simply whatever your fancy is in terms of how you lay out the UI.

Referencing the value of a hyperlinked text box

So I'm having some difficulties with this code. I know it's obnoxiously wordy, but every attempt I made to turn some of these form references into variables to save space ended with me having even less functionality than before.
Basically what I've done so far is create a navigation form with several tabs, one to create a ticket, one to resolve/edit a ticket, and one to search the tickets. The search tab is basically a continuous form that updates based on the search criteria I enter. My goal is that when I click on the ticketID for each record, it will take me to the selected record on the Resolve/Edit Ticket page (on that page I have a combo box [called cboGoToRecord] where you can select the record you want).
I have a hyperlink in place that takes the user to the Resolve/Edit page and code that works ONLY when the line I've denoted with four asterisks (for clarity) is replaced with
rst.FindFirst "ticketID =" & [some number].
When I do that, the results are as expected. If I leave it as it is below, every record looks up the first record (A Debug.print check shows that the value of this field is apparently always 1...) So I guess what I need to figure out is how do I access the ticketID hyperlink's value so that I can put it on that line and make my code function effectively? I apologize if this is overly detailed but figured too much was better than not enough.
Private Sub ticketID_Click()
'Takes user from Search Tickets to Resolve/Edit Issues tab
DoCmd.BrowseTo acBrowseToForm, "frmResolveIssues", "frmBrowseTickets.NavigationSubform"
On Error Resume Next
Dim rst As Object
Set rst = Forms!frmBrowseTickets!NavigationSubform.Form.RecordsetClone
[Forms]![frmBrowseTickets]![NavigationSubform].Form![cboGoToRecord].Value = [Forms]![frmBrowseTickets]![NavigationSubform].Form![ticketID].Value
****rst.FindFirst "ticketID =" & [Forms]![frmBrowseTickets]![NavigationSubform].Form![cboGoToRecord].Value
Forms!frmBrowseTickets!NavigationSubform.Form.Bookmark = rst.Bookmark
Debug.Print [Forms]![frmBrowseTickets]![NavigationSubform].Form![ticketID].Value
End Sub
Edit:
After altering my form to add a separate hyperlink and referencing the static ticketID, I have concluded that everything I thought was true was not. Finding the value of a hyperlink was NOT the problem. The problem is that my ticketID value truly does insist on being one, and I have no clue how to fix that.
When this works:
Debug.Print [Forms]![frmBrowseTickets]![NavigationSubform].Form![ticketID].Value
then also check out:
Debug.Print [Forms]![frmBrowseTickets]![NavigationSubform].Form![cboGoToRecord].Value
As June7, I never use the Navigation form. It complicates everything too much.

Access 2007 textbox is seen as empty while it is not

I was searching for my question for hours and I have found some ideas but it still doesn't do what I want.
I have a form "AddWorker" with texboxes "Name", "Surname" and so on.
At the end of this form I decided to use a button to handle addition to database by VBA code.
When I put some data into texboxes I can refer to them by textbox.text property, but only if I am focused on this texbox. In other cases I can use textbox.value property.
In my case when I put all data into 3 textboxes I clik button "Add worker" to add person to database, but last textbox (for example 3) is seen as empty because it did't see text I have put into textbox. I need to clik into another textbox (for example 2 or 1) to create "some event" and then it update textbox 3 and all data can be read in vBA.
What can I do to see all texboxes filled in VBA when i click "Add worker" button.
I have found some example but it didn't help me a lot. I still see empty textbox while clicking "Add worker" button.
Textbox null problem
First of all, make sure the form is unbound. It should not have a recordsource associated with it.
Then, try adding a few messageboxes in the code behind the Add Worker button. Something like:
Sub Add_Worker_Click()
msgbox "Text1: " & Me.TextBox1.Value
msgbox "Text2: " & Me.TextBox2.Value
msgbox "Text3: " & Me.TextBox3.Value
/* Comment out all of your code for now */
End Sub
Give that a shot and see what is in the textboxes. Then replace ".Value" with ".Text" and see what you get.

cascading combo box causing empty fields in next record

I'm having problems with a cascading combo box. Everything works fine with the combo boxes and the values get populated correctly.
Private Sub cmbAdjComp_AfterUpdate()
Me.cboAdjOff.RowSource = "SELECT AdjusterCompanyOffice.ID,
AdjusterCompanyOffice.Address1,
AdjusterCompanyOffice.Address2,
AdjusterCompanyOffice.Address3,
AdjusterCompanyOffice.Address4,
AdjusterCompanyOffice.Address5 FROM" & _
" AdjusterCompanyOffice WHERE
AdjusterCompanyOffice.AdjCompID = " & Me.cmbAdjComp.Column(1) & _
" ORDER BY AdjusterCompanyOffice.Address1"
Me.cboAdjOff = Me.cboAdjOff.ItemData(0)
End Sub
The secondary combo box has a row source query:
SELECT AdjusterCompanyOffice.ID, AdjusterCompanyOffice.Address1,
AdjusterCompanyOffice.Address2, AdjusterCompanyOffice.Address3,
AdjusterCompanyOffice.Address4, AdjusterCompanyOffice.Address5 FROM
AdjusterCompanyOffice ORDER BY AdjusterCompanyOffice.Address1;
Both comboboxes have the same controlsource.
Everything works fine and dandy moving between records and the boxes show the correct fields for each record.
When i use the first combo box, and then select the appropriate option in the second combo box, everything works great on the specific record.
However when I move to the next record, the values in the second combo box are all empty. If i close the form and reopen it, and avoid using the cascading combo boxes all the values are all correct when i move between records.
Somehow using the cascading combo boxes creates a conflict with the row source of the secondary combo box.
Hope that is clear! Have been rummaging around for an answer but cant find anything.
any help would be greatly appreciated.
Thanks
Noel
The reason why the combo box is blank when you navigate to the next record is because you have NotInList set to TRUE (which is what you want), but when you arrive on the record, the rowsource has been filtered to not include the value stored in the field the combo box is bound to. Thus, it's blank -- the value is there, but it can't be displayed, since it's not in the list.
To fix this, you need to clear the filter on the second combo box. To do that, in the OnCurrent event of your form, set the rowsource of the filtered combo box to be unfiltered:
Me!cboAdjOff.RowSource = "SELECT AdjusterCompanyOffice.ID, AdjusterCompanyOffice.Address1, AdjusterCompanyOffice.Address2, AdjusterCompanyOffice.Address3, AdjusterCompanyOffice.Address4, AdjusterCompanyOffice.Address5 FROM AdjusterCompanyOffice ORDER BY AdjusterCompanyOffice.Address1"
I usually handle this by creating two constants at the top of the form's module, one for the SELECT statement and one for the ORDER BY:
cstrRecordsourceSelect = "SELECT AdjusterCompanyOffice.ID, AdjusterCompanyOffice.Address1, AdjusterCompanyOffice.Address2, AdjusterCompanyOffice.Address3, AdjusterCompanyOffice.Address4, AdjusterCompanyOffice.Address5 FROM AdjusterCompanyOffice"
cstrRecordsourceOrderBy = "ORDER BY AdjusterCompanyOffice.Address1"
Then it's much easier to handle. In the OnCurrent it looks like this:
Me!cboAdjOff.RowSource = cstrRecordsourceSelect & " " & cstrRecordsourceSelect
...and in the AfterUpdate of your first combo box:
Me!cboAdjOff.RowSource = cstrRecordsourceSelect & _
"WHERE AdjusterCompanyOffice.AdjCompID = " & Me!cmbAdjComp.Column(1) & _
" " & cstrRecordsourceSelect
This makes the code easier to read, and it also makes it easier to alter the rowsource if you need to, since you have to edit only the constant.