Modules & VBA :: Most Often Value In A Field
Mar 2, 2014How can i get the value that is used most common in one column of the table through vba code?
View RepliesHow can i get the value that is used most common in one column of the table through vba code?
View RepliesI want to filter my subform data, to only show records where field A is a higher value than field B.
Code:
Me.MySubform.Form.Filter = "A > B"
Me.MySubform.Form.FilterOn = True
This way it doesn't find field B.
Code:
Me.MySubform.Form.Filter = "A > " & MySubform.Form!B
Me.MySubform.Form.FilterOn = True
This way it seems to filter all record to the field B value of the first record.
I am trying to do some simple table operations. I have a field (Date) containing dates, and an empty field called Day.
I want to extract the day number from the Date field, and write it to the Day field.
I didn't get very far until I ran into trouble when setting my recordset. I get the error "Too few parameters, expected 1". Clicking "Debug", will highlight the code line "Set rs = db.OpenRecordset(sqlString, dbOpenDynaset)".
So far, my code looks as follows:
Code:
Private Sub Command16_Click()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim sqlString As String
Dim dataDay As Byte
'Open connection to current Access database
Set db = CurrentDb()
[Code]...
I am not very familiar with the various types of recordset settings. I just want to be able to read data from the Date field, and write data to the Day field.
I am trying create some code that checks if the contents of the status field in a table is "Authorised" where the ID = something specific for multiple records. If all records witht the specific ID are "Authorised" Then generate a new record in another table. Where to start, perhaps a Dlookup?
View 1 Replies View RelatedUsing Access 2010. Fairly new to automation and macros.I have two tables (tblProductReceived and tblBins) and a form (frmProductReceived).A field in tblBins corresponds to a location the bin is at (named BinLocationID) and the tblProductReceived table tracks product that a specific bin has received.
What I need is for the tblProductReceived field PRLocationID ([tblProductReceived].[PRLocationID]) to be automatically populated with where the bin is at ([tblBins].[BinLocationID]) when selecting a specific bin in the form (frmProductReceived).
I have a form that users will use to add new records (customers).
There is a field named VAT_Registration_no
First of all i want some code to check for duplicates in that field only,before entering the next field.If the record exists i want to show a msgbox and set focus to the vat_registration_no field. Also I want the same thing to happen if the vat_registration_no field is empty.here is what i have tried:
Private Sub VAT_registration_no_AfterUpdate()
Dim btest As Boolean
If VAT_registration_no = "" Or IsNull(Me.VAT_registration_no) Then
MsgBox "Please enter a Vat Registration No.", vbOKOnly, "error"
Me.VAT_registration_no.SetFocus
Else
btest = True
End If
End Sub
and to all other fields:
Private Sub textfield_Enter()
If Not btest Then
Me.textfield.SetFocus
End If
End Sub
If I just press enter to go straight to the second field I dont get a msg. If I write something and delete it and press enter i get the msg but when I press ok the cursor goes to the next field. I want it to go to the vat_registration_no field again. And I also want this to happen even if dont write something and then delete it.
Is there a way to remove data from one or multiple fields if the value of a separate field IsNotNull?
View 2 Replies View RelatedI have 2 tables, "Counselors" and "Appeals". There are several names in the Counselor table but it is not a fixed number of names (rows) usually around 7. There is also some variable number of records in the Appeals table, could be 0, could be 50, depending on the day.
I need to, in a round robin fashion, assign the counselor names one by one to the records in the Appeals table. How to loop through the 2 tables and update the name field in the Appeals table with the name in the Counselor table.
I have a form and a VBA event in which I would like to update a field in the current record. However, the field name is stored as a variable so I can't just use Me!FieldName = __
I've tried simply the following, but get a "No current record" error. why I'm getting the error, but how do I select the record currently visible in the form to edit?
Code:
foo = "bar"
Me.Recordset.Edit.Fields(foo) = True
I have the following fields in an A2010 form
PaymentMethod
Total
InstalmentAmounts
OurFee
InstalmentAmounts field is populated based on the results of PaymentMethod which is a combo box
Here is the current code
Select Case Me.Payment_Method.Value
Case "Three post dated Cheques"
'If three payments by cheque
Me.InstalmentAmounts.Value = Round(Me.Total.Value / 3, 2)
In some cases there will be a few pennies that the client "overpays" because the instalment amounts will not add up to the Total. I need to add up the TotalInstalmentPayments to find out what the client actually pays and then add the difference between TotalInstalmentPayments and Total to the OurFee field
So
Total = 500.00
Payment Method = 3 instalments so
IstalmentAmounts = 166.67 (rounded) so client pays 500.01 so the 0.01 needs to add to the OurFee field.
I am trying to create a simple budget planner. So far, I have the following table:
tbl_account [id|acc_type|acc_name|balance|memo]
tbl_expense [id|exp_date|exp_amt|exp_acct|exp_payee|exp_type]
tbl_expense_cat [id|cat_name|cat_type]
tbl_income [id|inc_date|inc_amt|inc_acct|inc_payee|inc_type]
tbl_income_cat [id|cat_name|cat_type]
The relation now are:
[tbl_account:id] ---> [tbl_income:exp_acct] --> [tbl_income:id]
|_______> [tbl_expense:inc_acct] --> [tbl_income:id]
I have 3 subform on the main form:
[account_sf]
[expense_sf]
[income_sf]
I have set all them to continuous. Now I have added 3 account in the tbl_account.
I wonder how to SUM all the income of certain account, and minus all expense of certain account, and have them showed in the subform tbl_account.
Here is the attach pics: Untitled.jpg
create a new field programatically, transfer all the data from the old field into it and then deleting the old field. because my field is a text field and i want it to be a number field. I think i can add a new field and delete the old field. But i don't know how to do the vb code part as in where to find it and where to put it.
View 6 Replies View RelatedI am trying to write a statement and it returns: #Type!. I know what this means but it should not give this error.I have button that copies a certain number of fields to the clipboard. The one below is one of them. Here is the coding I am using that works:
Code:
=Trim(IIf([CallingContactRel] Is Not Null,[CallingContactRel] & ": " & [CallingContact],[CallingContact]))
I would like to add the following condition to this code. I have a yes/no field called BookingNoteContactExcl. If this is ticked, it should exclude [CallingContact] from being copied, in other words, return "" in the code above.
I just wondering if there is any way to Dmax more than one field? I found something and tried it but it does not seem to work.
Text13 = 10
Text15 = 5
I expected to get a result of just 10 but didn't
Code:
Dim Junk As Variant
Junk = DMax("[Text13] & ', ' & [Text15]", "Test")
MsgBox Junk
I have access tool with front end and back end parts.My user works with forms in order to add new records or edit records.I wish to "catch" the following events - if the user modify field's value (which is not NULL) I wish to display a notification message and update a comment field / log table with old field data, new field data, time and user name. If the user update field's value from NULL to other value I do not need to log it.
Can I do it in the form level and not for each field ?I wish to discover the modified fields names and analyze their values before and after the update.
I'm lost on how to use the LIKE to find a value in a field.
I try to use the open folder if a field contains "Retail" or any other containing as a part. So, I could have just "Retail" "New Retail" and then act on it.
How can I use the below proper?
Code:
If Me.Business_Type Like "*" & "Retail" Then
I use the following 3 calls to add 3 fields to an Access db,
Code:
Call subCreateField("tblRootCanalTreatment", "lngMethodID", "dbLong", strPath, 606)
Call subCreateField("tblRootCanalTreatment", "txtReferencePoint", "dbText", strPath, 620)
Call subCreateField("tblRootCanalTreatment", "txtSpaceForPole", "dbText", strPath, 644)
The sub is indicated below,
Code:
Private Sub subCreateField(strTable As String, strField As String, strFieldType As String, strPath As String, lngVersion As Long)
Dim rstSerial As ADODB.Recordset
Set rstSerial = New ADODB.Recordset
rstSerial.Open "tblSerial", CurrentProject.connection, adOpenKeyset, adLockPessimistic
rstSerial.MoveFirst
If rstSerial!lngVersion < lngVersion Then
[code]....
Only the first field ("lngMethodID") gets created. The other two fields ("txtReferencePoint") and ("txtSpaceForPole") do not get created. If I exit the db before each sub call then all fields get added. Do I need to add some "refresh field" action or other action.
Is there a possibility to use a shorter code for extracting one field from one record, than opening a recordset, getting the field, closing it and setting the recset to "Nothing" again? I'm doing this multiple times in my code and it seems a bit too much for what it's supposed to do.
Code:
sql = "SELECT tblAdFlgDaten.* FROM tblAdFlgDaten WHERE (((tblAdFlgDaten.AuftrID)=" & ABAuftrID & _
") And ((tblAdFlgDaten.Schritt)=2))"
Set RSnap = dbase.OpenRecordset(sql, dbOpenSnapshot)
If IsNull(RSnap.Fields(2)) Then
...
...
End If
RSnap.Close
Set RSnap = Nothing
I inherited an old database. Not designed too well. Nearly 100 tables with different types of names. Some table names start with and "_", some with "tbl" and some just names.
I want to add a new field called "TimeStamp", date/time, and default value Now() to all the tables.
In my vba code i write this
If DLookup("Full_Name", "tbl_Personal_Information", "Full_Name = Forms!frm_New_Person!F_N") > 0 Then
'--------------------------
MSG = MsgBox("this client is existed and his id is {" & [P_ID] & "} ",
vbOKOnly + vbInformation + vbMsgBoxRtlReading, "client database")
Else
strsql101 = "insert into tbl_Personal_Information (Name_English, Father_English, Family_English, Mother_English,
P_ID, NName, Father, Family, Mother, Birthdate, Nationality, Record_Number, Record_Place, Address,
[Code] ....
My problem is the id in the msgbox give me the last id from tbl_personal_information
But what I want is the id of the client that i try to add...
I have a tblManualRewardIncident in there I have 3 fields I want to have my staff in put these rewards via a frmRewardIncidentEntry However im concerned over another staff member in putting the same data so I want the form to highlight on update that a duplicate is there already so cancel the data entry.
The 3 fields that need to check and match are StrataID , DateOfIncident , EndDateOfIncident these are all in the tblManualRewardIncident and appear as buttons in the form frmRewardIncidentEntry the buttons are as follows
cboStrataID , txtDateOfIncident , txtEndDateOfIncident
I want the VBA to run when I CLICK another button on same form cboSQCDP..All 3 fields must match exactly to flag a issue.
StrataID , DateOfIncident , EndDateOfIncident from tblManualRewardIncident
If it doesn't find a match continue and add the inputs in these boxes to the table if it finds a match flag a message and delete the data from the form.
I have some code in which I enter a startdate and a enddate into textbox's and a combo box where I enter a client name when I run the code it will show all record's generated with in the date range and same client name set in the combo box "cboclient" what I would like to be able to do is have another combo box call cboclient2 which will allow me to enter another client name so then when the report opens it will show me with in the date range set in startdate and enddate and filter the client field by cboclient and cboclient2 so for e.g.
startdate
01/01/14
enddate
11/01/14
cboclient
peter
cboclient2
steve
Run code show all record in date range and with client name peter and steve
Here's the code I have
Private Sub cmdPreview_Click()
'On Error GoTo Err_Handler 'Remove the single quote from start of this line once you have it working.
Dim strReport As String
Dim strDateField As String
Dim strWhere As String
Dim lngView As Long
Const strcJetDate = "#mm/dd/yyyy#" 'Do NOT change it to match your local settings.
[Code] ....
Why can't I get this simple piece of code to work?
Code:
Private Sub txtDateBack_AfterUpdate()
' updates loan status
txtLoaned = 0
If txtDateBack = Null Then txtLoaned = 1
End Sub
Code:
Private Sub txtDateBack_AfterUpdate()
' updates loan status
txtLoaned = 0
If txtDateBack = "" Then txtLoaned = 1
End Sub
I am looking for a piece of code (either in access or excel) which will return all combinations of records in a particular field (or column of cells) which will sum up to a given value (or a close approximation thereof - ie a margin of error of, say, 2).
In other words, imagine you have a number field with 100 records in it. I would like to know all combinations of those records which add up to a value that the code could specify (eg 223). This would be incredibly valuable to assist in performing reconciliations that I perform in my role.
I have a table with several fields including the following 3 fields:
dtmAppoint Date = stores appointment date
dtmAppointTime = stores appointment time
lngAppointDoctorID = stores doctor's id for specific appointment
When I enter a new appointment, I want to know whether a specific combination of these 3 fields already exists. The doctor is actually a dentist and maybe another appointment has already been placed for the same dentist on a different chair. Creating a recordset as indicated below works but I am having some problems with comparing Time (dtmAppointTime). The following works but I need to extract Hour, Minute and Second and put it into string variable strTimeDum.
Code:
rstSearch.Open "SELECT * FROM tblAppointment " _
& " WHERE (clng(dtmAppointDate) = " & CLng(rst!dtmAppointDate) & " )" _
& " AND (dtmAppointTime = #" & strTimeDum & "#)" _
& " AND (lngAppointDoctorID = " & lngAppointDoctorID & ");", CurrentProject.connection, adOpenKeyset, adLockPessimistic
Any way to retrieve the records that correspond to the specific time or a simpler way to access the records of interest?
I have a table with 100,000 plus unique rows and I want to add a column (call it 'ID') and place a value in each row starting with 000001 and adding one on to each row. What is the correct code to do this. I've tried with various combinations of For...next but can't get anything to work.
View 3 Replies View Related