Trying to design form to query and edit records Access - forms

I'm trying to make an Access database where we can scan in a list of bar-codes, batch edit information for them, then save all the records. Later, they will need to be scanned again to batch edit more information such as shipping and order numbers.
Does anyone have suggestions on how to best design this? To start with, I've (1) made separate tables for "orders" and "parts" and (2) created a form of text boxes and a button attempting to apply this info to a part subform where records are created via the bar-code scanner. I'm a rather new Access designer. Thanks!
The questions are:
I'm not sure how to query these records via the bar code (Part_ID field) to apply order information to them later.
I can't currently update all new part records at once through my form.

Here's a little guide on how to do it. Let me know if you have any questions.
Dim db As DAO.Database
Dim Rs As DAO.Recordset
'Here is an example of a vba qarry in access. tblOrdersWhere is obviously your table.
'orderNum is a column name in your table pref a primary key
'txtOrderNum.Value is the value of a text box
'If you want just a simple select * from table you can put after db.OpenRecordset("tblOrders")
set rs = db.OpenRecordset("Select * from tblOrders Where orderNum like '*" & txtOrderNum.Value & "*';", dbOpenDynaset)
'This is how you update records in Access
'If you want to update it's Rs.Edit instead of Rs.AddNew
Rs.AddNew
Rs("OrderItem").Value = txtGroupName.Value
Rs("OrderTime").Value = txtGroupNum.Value
rs.Update

Related

How do I search forms in Access using values from another table that is being referenced?

The management staff in my department has been asked to record any and all errors committed by our team. I created a database to store them and a simple form for the management team to use to record each error. Several fields are referencing other tables such as Staff, issue category, root cause, etc...
We need to be able to search the forms for specific records to either update or review, and I have found the best way for us to search is by filtering the forms based on the individual who committed the error. Here is the code that I am using for the search button:
Private Sub SearchRecord_Click()
Dim Search As String
Search = InputBox("Please enter who committed the error", "Name", ErrorMadeBy)
If Search = "" Then Exit Sub
Me.Filter = "ErrorMadeBy = """" & Search & """
Me.FilterOn = True
End Sub
The filter works great, but instead of filling out the name, you have to use the ID number in the Staff table when filling out the Input Box. I'd like to be able to input the name (or part of the name) instead of having to have everyone memorize the ID numbers from the staff table.
What I do in these cases?
Fire up the query builder - left join in those extra tables (with the text parts in place of the id).
So be it a part number, quote number for a project etc? Just left join in those tables in the query builder and save that query.
Now, your search box and code can be somthing like:
dim rst as DAO.RecordSet
strSQL = "Select * from MyCoolQuery where PartName like '" & txtPartName & "*'"
set rst = currentdb.OpenRecordSet(strSQL)
if rst.EOF = false then
me.RecordSet.FindFirst "PartID = " & rst!PartID
end if
In fact, you can even often left join in those extra tables right into the current form, and even use ctrl-f to search if the said text boxes are place on the given form. However, I tend to separate out the search process from the actual form. So I might build a search form, say like this:
So in above, they can search say by a Hotel name, or project name or whatever. Becuase the one query has the text parts, then they can be searched. But I put the query results into a grid and each row of course has the PK ID, and thus a search could result in 10 matches, they are now free to click on any row - and i jump to the form to display the one records.
eg: the row click button does this:
docmd.OpenForm "frmTourBooking",,,"ID = " & me!ID
So, this makes for a great work flow. Users search, see, pick and then jump to the form with the one record, and then close and return back to search form - and often it has the several "hits" from that search that you want to work on anyway.

Take value from field in Form to a new record in other Table

Would really like some guidance on this one. Not as easy as the title might say at first and I'm stuck beyond all and frustrated.
So:
I have a MainForm (With a current ID I would like to stay on!)
I have a Subform (search engine that searches in various linked excel files)
I have 2 tables; one for the Mainform, and one for Items
So on the Mainform, I display the Subform (search).
I do my search and find a specific item in the excel files
I have a command button, that I want to click save the found item in the search field, into my ItemsTable as a new record.
Currently I'm doing this:
Private Sub Command13_Click()
Forms!MainForm.Form.Item1.Value = Me.Searchresult.Value
End Sub
This does actually post my search result into a new field and saves it into the itemsTable.
My problem: I don't need to actually have a field to post to. I just want it to write directly to my table and store it there as a NEW record. (Right now it just overwrites the previous data. Logically because its the same field every time with the same properties).
Can someone PLEASE help me with this one?
Options:
set focus to the subform container then move to New Record row followed by your code, this is not simple, review https://access-programmers.co.uk/forums/showthread.php?t=127337
use SQL INSERT action then requery the subform
CurrentDb.Execute("INSERT INTO Items(Item1) VALUES('" & Me.Searchresult & "'")

How to add a multiple values field to an MS Access form

I have a database which records and tracks the training records for each employee within our group of companies.
One of the forms on the database is 'add training record' and currently this is done per person ID, adding the course id, date, certificate, etc. What I would love to do is be able to add multiple person IDs, as a number of people can attend the same course/ date, so I have to add the course details in many times, which is very time consuming and annoying.
You're going to need extensive VBA behind the scenes to do this, as well as a couple of controls to make your life easier (multi-select combo or list boxes). You could do it in a text box if you want, using the semi-colon between User IDs.
Since the text box is easier, let's look at that. What you would do is have something like this behind the Submit button:
Dim db as Database
Dim rec as Recordset
Dim str as String
Set db = CurrentDB
Set rec = db.OpenRecordSet("SELECT * FROM tblMyTable")
'Throw the User IDs into an array
Dim var As Variant
Dim i As Long
str = me.txtUserIDs
var = Split(str, ";")
'For every User ID, add a new record to the database
For i = 0 To UBound(var)
rec.AddNew
rec("UserID") = var(i)
rec("CourseID") = Me.txtCourseID
rec("CourseDate") = Me.txtCourseDate
'ETC... adding fields as needed
rec.Update
Next i
This is completely off-the-cuff and (of course) requires you to change the appropriate variable names, but it should give you a solid outline for how to solve the problem.

Sub-Forms in MS Acess

Background: I have two tables. One has a list of clients and some basic client attributes (tblClient). The second has a list of products. Each client can have multiple products so I have a one to many relationship here where the primary key (client name) is the foreign key in the product table.
What I'm looking to do: I'm looking to create two forms. The main form will have a snapshot of clients and have a small nested table to provide a summary of all the products. This I have completed successfully. I have also made a second form in which all the details associated with products can be put in (matching the products data table). What I want to do is to have a button on the main client form that when clicked opens up the product form ONLY to the products currently used by the client. If there are no product, it opens to a blank form with some pre-filled information (i.e. client name). For example, if I'm reviewing customer John Doe and he currently has product A, B, and C, I want to click a button to have the product details specific to John Doe pull up. If he has no products, I'd like Access to open up a new entry product form for me with John Doe's name filled in already to avoid confusion.
I'm very new to access, any help would be very much appreciated.
thanks,
Z
I'm assuming your 2nd form is linked to a table? If so, just filter the recordset when you open it.
For instance, the OnClick event of your button will look at the current ClientID and open the form based on that ClientID.
Dim stDocName As String
Dim stOpenArg As String
'Make stDocName the name of the form you're going to open
stDocName = "frmAssignProject"
'Make stOpenArg your variable to filter on
stOpenArg = Me.ClientID
DoCmd.OpenForm stDocName, , , , , , stOpenArg
Then, in the OnLoad event of your second form, filter based on your OpenArg:
private sub form_load()
Dim rs as DAO.Recordset
Me.RecordSource = "Select * From tblProducts Where ClientID = " & OpenArgs & ""
Set rs = Me.RecordsetClone
'This is where it determines if it should pull in the data from the previous form
If rs.RecordCount > 0 Then
else
Me.ClientID = Forms!frmClients.ClientID
Me.ClientName = Forms!frmClients.ClientName
etc...
end if
end sub
The above is entirely "air code", it will probably need some tweaking but the concept is sound.

How to create a universal MS Access form?

I have a database that has a two tables which differ only in several fields so I thought of creating a single form for them and adding an option group (radio switch) witch would determine to which table the data from fields should go. The thing i I dont know how to hange the destination and some field should be hidden or at least on one but not another option.
This gave me an idea that for small databases this could be used to create universal form.
How to control data destination from form field in MS Access depending on option goup?
You can call different tables based on variables you create in a blank form. Here's an example if you use the table name in a combo box.
Dim var as String
Dim myR as Recordset
var = me.combo_box_name.column(0)
Set myR = CurrentDb.OpenRecordset (var, dbOpenDynaset)
'Code here based on variable, use an if statement if you want
Set myR = Nothing