Double Click list box to Open Form to Specific record - ms-access

I have a list box that displays my entire Access databases records with a brief descriptions in additional columns. The first column (0) has the record identifier (PART NUMBER) which is the primary key in the table. I am trying to get the double click event to open the "SETUP SHEET DATA ENTRY" Form to the specific row in the list box. The part number is classified as text and not numerical. I don't know what the problem is and any advice would help.
List box name = Listallpart
Primary key in table name = PART NUMBER
Table name = Setup Sheet History
Form name = Setup Sheet Data Entry
Private Sub Listallpart_DblClick(Cancel As Integer)
DoCmd.OpenForm "SETUP SHEET DATA ENTRY", , , "[PART NUMBER] = " & Me.Listallpart.Column(0).Value
End Sub
I have another question very similar....
Private Sub Listallpart_DblClick(Cancel As Integer)
Dim strpn As String
Dim strco As String
strpn = Me.Listallpart.Column(0)
strco = Me.Listallpart.Column(1)
DoCmd.OpenForm "SETUP SHEET DATA ENTRY", , , ("[PART NUMBER] = '" & Me.Listallpart.Column(0) & "'" And "[CURRENTOPERATION] ='" & Me.Listallpart.Column(1) & "'")
End Sub
The code above is for another mod to the code. Every record has these 2 required unique fields. I am getting a "run time error "13" mismatch type". I added the two variables in the beginning to make sure the values are correct. I inserted break points and confirmed the values. The data is numerical.

Since [PART NUMBER] is a text field, add quotes around the list box value in your OpenForm statement.
DoCmd.OpenForm "SETUP SHEET DATA ENTRY", , , "[PART NUMBER] = '" & Me.Listallpart.Column(0).Value & "'"

Your second question is the inverse of your first question; seeing as [CURRENTOPERATION] is numeric you don't need to add the quotes to this in your OpenForm
DoCmd.OpenForm "SETUP SHEET DATA ENTRY", , , ("[PART NUMBER] = '" & Me.Listallpart.Column(0) & "'" And "[CURRENTOPERATION] =" & Me.Listallpart.Column(1))

Related

Access - goto a recordset found in a searchbox

Okay I am working with Access 2021, VBA programming ist more than a decade ago so I need some basic help.
I'm having
a table tblMyData with the fields ID, Name, givenName
a form frmMyForm with those fields
a pop-up search box which gives the search results in a list box 'lstItems'
if I double-click on a list item, Me.lstItems.Value gives me the actual ID of the record, not the record number.
Now I want the underlying form (frmMyForm) to go to the recordset with this ID.
frmMyForm.FindFirst "[ID] LIKE 'Me.lstItems.Value'"
(which throws me an error, [variable not defined])
or something like
DoCmd.GoToRecord acDataForm, "frmMyForm", acGoTo, Me.lstItems.ID
(which throws me an error, [method or variable not defined])
I tried any combination of the above objects, but cannot reside.
If your ID is numeric:
Me.Recordset.FindFirst "[ID] = " & Me.lstItems.Value ' E.g. "[ID] = 7"
If it is a text:
Me.Recordset.FindFirst "[ID] = '" & Me.lstItems.Value & "'" ' E.g. "[ID] = 'abc'"

Hide records that are not matching search box filter

I am using MS Access 2010.
I have a table named "Dashboard"
I have a field named "Client Name"
In my tab named "Search Form" I have a subform called "Dashboard_subform"
The code is working corectly but I have two minor issues:
1. When combo box is empty and i press enter then Run-time error "Extra ) in query expression '([Client Name] = )'.
2. All records are showing up when the combo box is empty. I want no records to show up until i search the particular field data is typed in the combo box. Only records matching the data typed in the combo box must be listed.
Private Sub SearchClientRecords_AfterUpdate()
Me.SearchClientRecords.AutoExpand = False
Dim myclient As String
myclient = "Select * from [Dashboard] where ([Client Name] = " & Me.SearchClientRecords & ")"
Me.Dashboard_subform.Form.RecordSource = myclient
Me.Dashboard_subform.Form.Requery
End Sub
I assumed "AutoExpand" False will hide all records until a entry is typed in the combo box.
Also not sure why the run time error is showing up because the closed paranthesis is needed in this case.
Try using this code (Assuming client name is never empty field and always has name)
Private Sub SearchClientRecords_AfterUpdate()
Dim myclient As String
If Not IsNull(SearchClientRecords) Then
myclient = "Select * from [Dashboard] where ([Client Name] = " & Me.SearchClientRecords & ")"
Else
myclient = "Select * from [Dashboard] where [Client Name] IS NULL"
End If
Me.Dashboard_subform.Form.RecordSource = myclient
Me.Dashboard_subform.Form.Requery
End Sub

How to record unbound control to a database

I have a form control (address) that uses Dlookup to call info from a table "database" but the form is bound to table "Tracker". The dlookup is based on another control on the same form - "Name" I need the form to record this dlookup control, along with other controls that are bound to "tracker" as new recordto the table "tracker."
My failed attempts:
Using the default value property to assign the recalled data from the dlookup to another text box which would be bound to "tracker" This simply does not work for some reason. Perhaps I am missing something that tells this control "Address" to update upon selecting the correct "name?"
Code:
Private Sub SubmitReferral_Click()
On Error GoTo Err_SubmitReferral_Click
DoCmd.GoToRecord , , acNewRec
Exit_SubmitReferral_Click:
Exit Sub
Err_SubmitReferral_Click:
MsgBox Err.Description
Resume Exit_SubmitReferral_Click
End Sub
I also tried this - to assign the data - but the data from the dlookup in control "Address1" is not transferring/copying to control "Address2"
Private Sub Combo276_OnUpdate()
OnUpdate ([Address2].Value = [Address1].Value)
End Sub
Help or suggestions?
PS - I have tried to Edit per request to be as specific as possible, and to follow proper board etiquette.
Still unsure of your field names, etc., but the following is an example you can modify. Change 'tblEmployee' to 'database'.
I must state that if you are just starting out with developing in Access (or VBA) that you should never use names that are reserved words, or that can be misleading. Your table named 'database' is ok if named 'tblDatabase'.
Option Compare Database
option Explicit
Private Sub cmdInsert_Click()
Dim strSQL As String
Dim i As Integer
Debug.Print "cmdInsert; "
i = MsgBox("Do you want to add 1 row for Employee ID: " & Me.EmpID & " to table 'tracker'?", vbYesNo, "Confirm Add")
If i = vbNo Then
Exit Sub
End If
DoCmd.SetWarnings True
strSQL = "INSERT INTO tracker ( FirstName, LastName, Add1, City, St, Zip ) " & _
"SELECT tblEmployee.FirstName, tblEmployee.LastName, tblEmployee.Add1, tblEmployee.City, tblEmployee.St, tblEmployee.Zip " & _
"FROM tblEmployee " & _
"WHERE (((tblEmployee.EmpID)=" & Me.EmpID & "));"
DoCmd.RunSQL strSQL
End Sub
Thanks for the help - I solved my concern by hiding the fields that contain the dlookup, and putting code behind a button that copies the information to fields that are bound and therefore will record to the table "tracker"

access combobox values not showing

I am trying to create a form with 3 combo boxes on which will run a report from existing data. The combo boxes will filter down based on the data chosen in the next level up combo box.
However I'm having issues with the Batch Number Combobox not populating it's list
Now this is my VBA script:
Private Sub Form_Load()
Me.cboDate.RowSource = ""
Me.cboBatchNo.RowSource = ""
End Sub
Private Sub cboBottleNo_AfterUpdate()
Dim sDateSource As String
sDateSource = "SELECT [tblNewCC].[Date] FROM [tblNewCC]" & _
" WHERE [tblNewCC].[BottleNo] = " & Me.cboBottleNo.Value
Me.cboDate.RowSource = sDateSource
Me.cboDate.Requery
End Sub
Private Sub cboDate_AfterUpdate()
Dim sBatchSource As String
sBatchSource = "SELECT [tblBatchTotals].[BatchNo] FROM [tblBatchTotals] INNER JOIN [tblNewCC] ON [tblBatchTotals].[RunNo]=[tblNewCC].[RunNo]" & _
" WHERE [tblNewCC].[BottleNo] = " & Me.cboBottleNo.Value & _
" AND [tblNewCC].[Date] = " & Me.cboDate.Value
Me.cboBatchNo.RowSource = sBatchSource
Me.cboBatchNo.Requery
End Sub
From what I can see this is working alright on the vba side as I can see it replacing the rowsource of the batch number combobox, and in datasheet view it is giving me results.
However the combobox isn't showing anything in it's list....
Unless I go in make a change and save the sql query again.
Any clues?
The last part of sBatchSource should be " AND [tblNewCC].[Date] = #" & Me.cboDate.Value & "#" As an aside, 'Date' is a terrible name for a field. It is a reserved word in Access and will eventually cause you problems. Here is a helpful link http://www.fontstuff.com/access/acctut15pfv.htm

MS access to view all record history data with the specific input field value but it is showing only first record of criteria

I tried to display a list of all requests from a specific dept of my table
So I created a form with all the tbl fields that I want to display on the form view of "details" section like this .
dept name Totalnum req# ticket
Then I have created a combo box with pre-defined values as 'depttest' field.
Then I used the following code on change value of field but form is displaying only the first record of the category and not showing all the records .... can some one please help me with this logic..
Option Compare Database
Option Explicit
'Set default record source of form
Const strsql = "SELECT tbl.dept,tbl.name,tbl.[Totalnum],tbl.[req#],tbl.[Ticket] FROM tbl"
Private Sub depttest_Change()
Dim strFilterSQL As String
strFilterSQL = strsql & " Where [dept] = 'me.depttest.value';"
Me.RecordSource = strFilterSQL
'DoCmd.RunSQL strFilterSQL
Me.Requery
End Sub
You are passing me.depttest.value as a string not a value. Try:
strFilterSQL = strsql & " Where [dept] = '" & me.depttest.value & "';"