Access 2010 VBA Form Pulling In Table Data - ms-access

I have an "Invoices" table, which I run an "Invoices From off of to create invoices for my clients. All my client data; address, hourly rate, etc. is on my "Client Lists" table. The Tables are linked together by a common account/client ID.
I don't want to update general items like hourly rate, address, every time I create an invoice. I am looking to set up an after update event that will auto populate these general items from my "Client Lists" table when I enter the client ID on the "Invoices" form.
---Update---
Below is the code I am working with, and I keep getting an error "Expected: list separator or).
In normal speak; The service type field on my "Invoices" form, should look at my Service type field, on my Client Lists table, for the same Client ID as Account ID.
Private Sub Client_ID_Change()
Service_Type = DLookup("Service_Type", "Client Lists", "Account ID=" & Client ID)
End Sub

Have you tried anything?
The short answer is:
create a query to represent the data you want. In vba use a recordset to run the query's logic for the ID you've got, then display the returned data in the recordset on your form.
However there's no detail here, as you have little yourself

Syntax error on the dlookup function.
To specify a search criteria (last parameter of dlookup) based on a field that contains a blank space, you will have to enclose it in brackets. Also consider that control names can have blank spaces, but to reference them in vba you must replace write them using underscores.
"[Account ID]=" & Client_ID
I would strongly suggest you name table fields and form controls without blank spaces.

Related

Alter Large Block of Records with Data Macro

Several hundred records were incorrectly entered into a table in my Access Database.
A particular ID number includes a two digit leading code that designates the state that record is from; so 01-24586 is a record from the ACT, and 02-55719 is a record from NSW. The incorrect entries have these two switched. I need to replace the first two digits of these records' IDs with the correct code.
To do this, I've tried to write a Named Data Macro that I can call from a regular macro object (so I can double click it in the navigation pane). I've done that, but it doesn't seem to work. My Data Macro (just one of the State fixes) looks like this:
If [State]="NSW" Then
For Each Record In tblCustomer
Where Condition =[State]="NSW"
Alias NSWCust
EditRecord
Alias NSWCust
SetField
Name MyobID
Value = "02-" & Right([MyobID],5)
End EditRecord
End If
When I call it from the other macro, using RunDataMacro it gives me error 3709.
Is this a bad way to go about fixing this? What's wrong with my execution?
Data macros are intended to be used as "triggers" (perform an action when a specific event occurs.
In order to update data, you should use an update query.
Statement would look like this:
UPDATE tblCustomer
SET MyobID = "02-" & Right([MyobID],5)
WHERE [State] = "NSW"

Access, lookup for data in another table if matches

I have a Union query with invoice data like invoice number, supplier and so on. This query is created for the purpose of providing credit note information.
My problem arise when I would like to provide exchange rate for invoices in different currencies. If there is for example RON currency, I need to check currency and date of invoice and then provide value from another table.
I stored currencies and their values in another database. I wanted to use Dlookup function but it works only current database. Not sure what can I do. Is VBA needed here or it can be avoided?
Edit:
Having problem with syntax:
Query:
SELECT [Faktury].InvoiceNumber, [Faktury].InvoiceDate, [Faktury].InvoiceCountry, [Faktury].Currency, DLookUp("Value","Tabela1","Currency1 =" & [Currency]) AS Wyr1
FROM [Faktury];
Dlookup syntax:
DLookUp("Value";"Tabela1";"Currency1 =" & [Currency])
Query has column with Currency used in invoice and Tabela1 has Currency1 and Value. I get error or no value is shown...
To access a a table in another database you can create a link to it:
Go to External Data > Access (although you could use any other type of data source) > choose the database file, and select Link to the data source by creating a linked table.
Then click Ok and select the table(s) you want to link (i.e. use in your database). Now you can use the table (Currency in my example) in your queries or in VBA like a normal table. For example with DLookup in VBA:
MsgBox DLookup("EuroValue", "Currency", "ID='" & InputBox("Currency?") & "'")
or in a (SQL) query:
SELECT EuroValue FROM [Currency] WHERE ID='USD';
or
SELECT DLookUp("EuroValue","Currency","ID='USD'");

Microsoft Access 2010 filtering data based on tempvar

i have a web database and im trying to filter a datasheet, based on the contents of a tempvar. Im trying to use the record source property of the datasheet to do this.
I need to do this because, every employee that logs in should only be able to see a given subset of data in the products table. In the employee table, i have an extra column with a string value which is the data that particular employee should see.
I have a login form that on clicking login, adds this string to the tempvars collection.I can see the tempvar has been added in the immediate window as shown below:
?tempvars!tmpgrpdsc -> "IAMS"
i use the query builder option to complete the record source property as shown below.
The problem is, nothing is returned !
But when i enter the string "IAMS", i get records returned.
However, i have done this with another datasheet and it has worked, the tempvar here held a number ! See below:
What am i missing or is there a better way to filter records based on the login. Thanks
What you showed should work.
However, have you tried to change the criteria to ="""" & [Tempvars]![tmpGrdsc] & """"
Also, to make sure that your tempvar is actually containing the data during the query, you could show it as a field, just to check exactly what data is being returned during the query:
SELECT Orders.*,
[Tempvars]![tmpGrdsc] AS TmpGrdsc
FROM Orders

Filtering A Lookup Field Based On Another Field

I have a lookup field in my table based on another table. I'm having trouble filtering those values based on another field that is entered prior to the field.
Is it possible to filter a lookup field based on another field?
EDIT
Let me try and clarify my original question, sorry about that. Ok, so I have a table1 that has the following fields: ID, Name, Logo.
If a user enters a specific name in the Name field, when they click on the Logo field, it'll only display those values associated that are similar to the name entered. Does that make any sense? If it does make sense, would there be an easier suggesion on accomplishing this task?
If you're talking about inside a table, the answer is "No". You can create cascading combo boxes on a form, but you can't base a lookup value in a field of a table off of a different field in that table (or the field in any other table).
Here is an example of how to handle filtering a combo box based on the value selected in another combo box:
I have the following form:
The combo boxes are named cboIntPN and cboManPN.
The Row Source for cboIntPN is set to: SELECT uniq_key, part_no, revision FROM inventor. The Row Source for cboManPN isn't set to anything.
When the user selects a value for Internal PN the following AfterUpdate Event is triggered:
Private Sub cboInternalPN_AfterUpdate()
[cboManPN].RowSourceType = "Table/Query"
[cboManPN].RowSource = "SELECT uniqmfgrhd, mfgr_pt_no FROM invtmfhd " & _
"WHERE uniq_key = '" & cboIntPN.value & "'"
End Sub
It sounds like he is having the same issue as me. I also wanted to filter a field in a table for data entry on another field's input and my conclusion is "it is time I stopped entering data manually in tables and begin to create Data entry forms. I was putting this task off until later, but if I don't do it now, I might make worse trouble for myself later.
Btw, what an old thread.

Access 2007 Add Record using same form

I am creating a simple invoice system in access. I currently have a form that I can use to view a particular invoice for a particular customer_id. I would also like to use this same form to add a new invoice. When the form is opened, I'd like it to already know that I want to use customer id #x. I already have the invoice table joined to the customer table on the "customer_id" field.
Currently when I open the form, it opens a blank invoice form that isn't tied to a customer at all. Basically what I want to know is, how to pass the customer ID to the form so it knows I'm "adding" a new record tied to an already-created customer ID.
(Normally I'm just opening the form, and it is already populated with the invoice details, and the customer info which is joined to the invoice details, I'd just like to be able to add a new record which is already tied to the customer)
You can pass an argument to a form when you open it by using the optional parameter OpenArgs of the DoCmd.OpenForm method.
In the form, you can get the value via Me.OpenArgs.
EDIT:
No, you just pass the value to OpenArgs, nothing else:
DoCmd.OpenForm([Invoice Detail],acNormal,,,acFormAdd,,1)
Unfortunately you can only pass one argument via OpenArgs.
If you need more, you have to do some tricks.
You need to quote your OpenArgs in your DoCmd.OpenForm method call:
DoCmd.OpenForm([Invoice Detail], acNormal, , , acFormAdd, , "[customer_id] = 1")