Modules & VBA :: How To Use Like Statement When Creating Record Set Of Data

Dec 17, 2013

how to use the Like statement when creating a record-set of data through VBA. Before I was always able to find work-arounds but now is the time to slay this issue once-and-for-all.A person can build several sales quotes for a specific company and I am trying to find the last sales quote that was built. The function is passed a variable length string and I am trying to build a recordset of all quotes based on the variable. Here is the offending line of code:

strSQL = "SELECT * FROM Quotes WHERE Quotes.ProposalNo Like " & "*" & strProposalBase & "*" & " ORDER By Quotes.QuoteID DESC" (This yields an empty recordset)

strSQL = "SELECT * FROM Quotes WHERE Quotes.ProposalNo Like ""*" & strProposalBase & "*"" ORDER By Quotes.QuoteID DESC" (This yields an Error message stating there is an invalid column name)

strSQL = "SELECT * FROM Quotes WHERE Quotes.ProposalNo Like " & strProposalBase & "*" & " ORDER By Quotes.QuoteID DESC" (This yields an Error message stating there is incorrect syntax near the word ORDER)

I have tried different variations above and beyond these strings and get one of the three listed errors.

View Replies


ADVERTISEMENT

Modules & VBA :: Using Record Number In Where Statement

Jul 8, 2014

I have a form with a sub form based on a query, in one of the fields i use a dbl click to open another form. I have use this in several areas in my DB but i having issues in one section of it not opening to the correct record. i tried a few things but i am limited to what i can use. The Record_Number is an Auto number and CLASS_Num is an entered number buy the user.

I have 2 things that i can use but i can not get the Record_Number to work. When i use the Record_Number i get an Data Type Mismatch Error.

----------------------------------------------------------------------
Private Sub Combo10_DblClick(Cancel As Integer)
DoCmd.OpenForm "Documentation_Form", acNormal, , "[Record_Number] = '" & Me.Record_Number & "' and [CLASS_Num] = '" & Me.CLASS_Num & "'"
End Sub
-----------------------------------------------------------------------

View 3 Replies View Related

Creating IIF Statement In Between Statement For Dates?

Apr 28, 2015

I am creating a multi-search form for a student database, where after I enter my search criteria I hit a "Run Query" command button and then it opens a query form with all of my criteria.So far I can search using last name, first name, and middle name. When I try to search with a start date and end date I am have issues.The start date and end date is for the class date. In the query form under the field, class date, for criteria I wrote:

Between IIf([Forms]![Search Form]![Start Date]="",1/1/10,[Forms]![Search Form]![Start Date]) And IIf([Forms]![Search Form]![End Date]="",4/25/15,[Forms]![Search Form]![End Date])

I want it when I write a date in the start date and end date I want it to give me a list of all the students who took the course between those dates. Also, if I leave the dates blank I want it to search all dates. The dates 1/1/10 and 4/25/15 are just the dates I gave because that is far back as my database goes.

View 11 Replies View Related

Modules & VBA :: How To Find Record In Table And Use One Of Its Field For If Statement

Jun 6, 2014

I have a table called login and inside that table is three columns: username, password and admin.

I have the username saved in a global variable called GsUser. How can i find the record in that table with the same Username as the string stored in GsUser and use that record for an if statement which sees if the value of the admin column is "Yes". Im trying to do it using VBA. Im not using a form where everything is bounded.

View 2 Replies View Related

Creating New Record From New Data In A Different Table

Oct 12, 2012

I have an access database that I use to manage my car dealership, part of it holds data of a stock vehicles, another aspect is invoicing.As part of the invoicing form, I have a part exchange vehicle section which creates a new record in the part exchange table.

What I would like to be able to do is when a new vehicle is added to the part exchange vehicle table it automatically adds it to the main vehicle table so it shows as a stock vehicle.

View 1 Replies View Related

Modules & VBA :: Apply IF Statement To Each Record In Detail Of Subform On Load

Jun 12, 2013

The problem I am facing is applying an IF statement to every record in the detail section of the subform.

I have the following code:

Code:
If Me.status = "CONFIRMED" Then
Me.course_ref.Enabled = False
Me.course_date.Enabled = False
Me.cmbModule1.Enabled = False
Me.cmbModule2.Enabled = False
Me.course_start_time.Enabled = False
Me.course_end_time.Enabled = False
Me.course_training_cost.Enabled = False
End If

This is in the on load event of the subform and works 'sort of'

Basically I have a record with the status of confirmed and records without this status, but the result of the if statement is being applied to all records. Is this because I need some sort of loop? and if so how would I loop through all records in the detail and apply this if statement to them all?

View 5 Replies View Related

Modules & VBA :: Error Message On Creating Duplicate Record

Jul 25, 2013

I need to be able to produce an error on a form where the user attempts to create a new user that already exists. The error needs to be produced when the save button is clicked.

See below for the existing code on my save button which exists in form, 'frmAddEditUser':

Private Sub cmdSave_Click()
If IsNull(cboManagerID) = True Then
MsgBox "Please select a manager", vbExclamation, "Details Missing!"
Me.cboManagerID.Requery

[Code] ....

Currently, if I attempt to create a user with the same Payroll ID as an existing user, my 'User details saved' message box is displayed and to the user it looks like a new record has saved successfully which isn't the case.

I need a message box to appear displaying something like "Payroll ID n already exists" where n is the 'PayrollID' of the duplicate record. (Is it possible to combine a value from a certain control and ones own custom text?)

Note: PayrollID is a combination of letters and numbers, i.e. two letters, followed by 5 numbers, e.g. JD12345.

For reference, the table/field and and control are called, '[tblUser].[PayrollID]' and 'txtPayrollID' (on 'frmAddEditUser') respectively; it is from this field and control that I want the error to be produced if the user is entering the same values which are existing in 'tblUser'.

View 10 Replies View Related

Modules & VBA :: Allow User To Select Record From Subform And Add It To Table - Insert Statement

Jun 18, 2013

I have a sub form with staff records on it within a main form. I am trying to allow the user to select a record from the sub form and add it to a table, here is my code which, to me, looks correct. However it gives me an error saying "Syntax error in INSERT INTO"

Code:
Private Sub Command3_Click()
Dim dbs As Database
Dim sqlstr As String
Set dbs = CurrentDb
Forename = Nz(Forms!frm_Capex_Submission!frm_staffSub.Form.shy_forename, "")
Surname = Nz(Forms!frm_Capex_Submission!frm_staffSub.Form.shy_surname, "")

[Code] ....

View 1 Replies View Related

Modules & VBA :: Insert Into Statement Using Data From Form Control?

Jun 29, 2014

I've got a form, user inputs a whole bunch of data and the data is stored into 2 different tables (using a form and subform), however i also need to copy a few fields from the subform into another table (as a new record) the table i intend to insert this data into (tblAdjustments) has four fields (that im interested in) Type, Reason, Quantity and Product (not the exact names) Type and reason are both just straight strings and will be the same each time, regardless of what the other two variables are, so i need type to equal "Finished Goods" and Reason to equal Produced further to that, the subfrom has 2 fields, batchPackedQTY (which will be quantity in the new table) and fgID (product in the new table

so i need an insert into statement that does this, ive tried INSERT INTO tblAdjustment (adjType, adjReason, fgID, adjQTY) ("Finished Goods", "Produced", Forms!SubFormBatches.fgID, Forms!SubformBatches.batchPackedQTY)

View 10 Replies View Related

Modules & VBA :: Insert Statement Not Saving Data To Tables

Jul 16, 2013

I am trying to create a form in which users can save new supplier data to a database. I am using two insert statements which insert similar data in to two similar tables. The insert statements appear to have no problems and no errors are produced upon execution yet the new data doesn't save into the tables. Here's the code;

Code:
Private Sub Command14_Click()
Dim sqlstr As String
Dim dbs As Database

[code]...

View 11 Replies View Related

Modules & VBA :: If Statement Not Return True Based On Data

Mar 14, 2014

I have a complex IF Statement within VBA. When I step thru the code the if statement variables should return true but instead treats it as False. See '>>>> this happens on the 2nd Pass of a Do Loop Statement, the First Loop the if Statement Returns True

Variable Values:

Record 1
contractNo: 00001634
nfld: 33.40%
nTier6: 30.00%

Record 2
contractNo: 00001634
nfld: 137.52%
nTier6: 28.50%

so the 2nd if should be true but it acts as false an moves to next If statement.

Code:

If nfld = Format(0, "Percent") Then
nOvrAmt = 0
BkOvrCalc = nOvrAmt
GoTo cont:
'>>> ElseIf nfld > nTier6 Then
nOvrAmt = rs.Fields("TotalNetUSExp") * rs1.Fields("T6E").Value

[Code] .....

View 1 Replies View Related

Modules & VBA :: Creating New Record Within Subform - Cannot Navigate To Other Active Records

May 4, 2015

I have a main form that controls 2 subforms. sbfActiveProjects displays a list of records that have not been flagged as complete. Upon clicking on a record in sbfActiveProjects, the details of that record show up in sbfProject. This functionality works great, except when I try to create a new record. The code works fine for getting a new record, however once I run the command I lose my ability to navigate to other active records.

Code:
Private Sub cmdNewProject_Click()
'set focus to sbfProject
sbfProject.SetFocus
'navigate to new record
DoCmd.GoToRecord , "", acNewRec
End Sub

View 2 Replies View Related

Modules & VBA :: Creating Report On Button Click With Appropriate Colour Of Each Record

Dec 10, 2014

I have access table that stores details as attached. Just to give an example how data is stored , I copied data from Access table to excelsheet. Now I would like to create a report that will run when a button is clicked on the form and the vba code should display the last 7 dates from todays dates in the report along with all the data and colour the record Green,Amber and Red depending upon the Update Date and Target Date. If the Target date exceeds then that records should be coloured "Red" and if todays date equals to Date then the record should be amber and if greater than Date but less than Target Date then it should be Green.

So the report should display the last 7 dates records from todays date and the appropriate color of each record to let everyone know if its under target, meets target etc.

View 4 Replies View Related

Modules & VBA :: Creating A Record And Then Updating With Additional Info In Various Fields

Apr 24, 2014

In the code below I am creating a record with the INSET INTO statement and then Updating with additional info in various fields. it is not working the way I thought it would, so I am trying to create the record in it's entirety.

Code:
SQL_Grade_GUSD_ID = "INSERT INTO Grades (GUSD_Student_ID) VALUES (" & Me.GUSD_Student_ID & ")"
SQLM1_1_ELA = "UPDATE Grades SET Grades.Subject = ""BM1(ELA)"""
SQLM1_2_ELA = "UPDATE Grades SET Grades.Type = ""Exam"""
SQLM1_3_ELA = "UPDATE Grades SET Grades.Score = ""0"""
SQLM1_4_ELA = "UPDATE Grades SET Grades.Nam = ""GUSD BM-1"""
DoCmd.RunSQL SQL

[Code] ...

I am running to syntax problems when I try to USE the INSERT INTO to create the record with all the info in one statement.

Code:
SQLM1_1_ELA = "INSERT INTO Grades ( GUSD_Student_ID, Subject, Type, Score, Nam ) " & _
"SELECT (" & Me.GUSD_Student_ID & ")"" AS GUSD_Student_ID, ""BM2(ELA)"" AS Subject, " & _
"""Exam"" AS Type, ""0"" AS Score, ""GUSD BM-1"" AS Nam " & _
"FROM Grades"

I am Getting this error:

Syntax error (missing operator) in query expression '(12345)" AS GUSD_STUDENT_ID,
"BM2(ELA)" As Subject, "Exam" AS Type, "0" As Score, "GUSD BM-1" AS Nam From Grades'

View 3 Replies View Related

Modules & VBA :: Creating A Search Form With Ability To Add Found Record To Table?

Aug 7, 2013

creating a VBA that will allow me to search for a record in Table A, and once the record is found, allow me the option to add that record to Table B. Is this possible to do if Table A and Table B are not formatted the same (i.e. one has more fields than the other)? In summary, creating a VBA that will allow me to search in one table and once the correct record is found, allow me the ability to add it to another table.

View 7 Replies View Related

Forms :: Stop Access From Creating New Record When Inputting Data In Field Or Tab

Dec 17, 2013

How do you prevent access from adding a new record when u input data in the current record or tab to the next field? My database is set up to open with a form where the user picks his name and then a week ending date once that is complete u open a new form where the name and date auto populate along with other fields to fill out such as job charge, charge type , times charged for each day of the week. But I don't want access to create a new record everytime the person inputs or tabs..... .

I have attached my database for better clarity!

View 9 Replies View Related

Modules & VBA :: Creating Recordset - Using Array As Report Data Source

Apr 17, 2015

I've done some basic work with arrays.. writing array data to form list objects.. How to use an array as a data source for a report?

Would i need to create a recordset and populate it with the array, then bind the report to it ?

The reason I am asking is the previous developer here built every app using arrays and UDT's... the apps are completely disconnected from the data. Everything is loaded in to arrays..

View 2 Replies View Related

Modules & VBA :: Data Entry - Subform Creating Orphan Records

Feb 13, 2015

How do I display a more meaningful message instead of the cryptic error about having to enter data into blah blah blah. How can I trap that error and provide them a more meaningful message about entering data. I have tried the following;

Main form name frmPatientRecords
Sub form name DentalRecords Subform
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Nz(tblPatientDetails!recordid, 0) = 0 Then
MsgBox ("sorry. Please complete the main record entry")
Parent.SetFocus
End If
End Sub

View 14 Replies View Related

Creating Dynamic Hyperlinks - Open Data Entry Form And Navigate To Specific Record

Nov 28, 2011

I have a form that lists records in a table. I would like to have a hyperlink beside each record that will open the data entry form and navigate to that specific record. Right now, the use can only open the form for all records and has to use the record navigation buttons to find the desired record.

View 1 Replies View Related

Creating An If Statement In A Table

Jun 6, 2007

I have created a database that tracks employee adherence. We have employees monitor adherence and when someone is out of adherence we track the time they are out and also there shift time. I am needing Access to know to change a record from 0:00 (midnight) to 23:59. I know it is probably done with an IF statement but dont know how to write it correctly, or where to place it.

View 1 Replies View Related

Creating SQL Statement To Create Table

Apr 19, 2007

Hey all

I have an online Access database and dont want to have to take it offline (download, update, upload) to create a new table.

Therefore I want to use a CREATE statement that I can run via an ASP page to create any additional tables.

I don't want to have to create the statements by hand so im looking for a way to create a table on my local version of access and export the SQL statement that would be used to create this table.

Any idea?

Thanks

View 1 Replies View Related

Reports :: Creating IIF Statement In A Report?

May 20, 2013

I am quite new to access 2007 but trying to create an IIF statement in a report but don't know where to start.

My report has lots of 'Label' fields with standard text based on a query for the fields components. I want one of my labels to only appear on the report for print IF a record field called 'Program' (which is from a list) has the word 'RHICHOP' at the beginning of it. If RHICHOP is not in the beginning of the Program then leave out the label text.

View 4 Replies View Related

General :: Creating Dynamic RibbonXML Where Statement Will Depend On User

May 17, 2015

creating dynamic RibbonXML where statement will depend on user that is accessing access database. I created DynamicXML no problem and it changes context depending on user but my main problem is refreshing ribbon. I see that UsysRibbons tables changes fine but it's not being loaded. I have to restart access in order to this to take effect. I tried gobjRibbon.Invalidate method but it doesn't refresh ribbon for some reason... Here is my code:I created new module with name "Ribbon" and put this in there:

Option Compare Database
Option Explicit
Public gobjRibbon As IRibbonUI
Public Sub CallbackOnLoad(Ribbon As IRibbonUI)
' Callbackname in XML File "onLoad"
Set gobjRibbon = Ribbon
End Sub

and then in form that validates a user I put:

If (Not gobjRibbon Is Nothing) Then
gobjRibbon.Invalidate
End If

View 7 Replies View Related

Modules & VBA :: Find Data And Add It As New Record

Feb 2, 2015

I have a unbounded form which has all the fields same as the table. Now I want to search a row from the table with the Ticket number and First Name. After retrieving all the fields instead of using Update query I just want to add it as a new record.

View 1 Replies View Related

Modules & VBA :: Check Data On New Record Entry?

Oct 14, 2014

We have a table, JobRegister that people enter information on using a form, FrmOrderEntry

I would like to run a check when a serial number is entered in the field SerialNo to see if the same serial number exists where CompletionDate is null.

this would stop duplicate open orders being put on the system, or new orders being entered where the previous order hasn't been completed.

View 14 Replies View Related

Modules & VBA :: Record Data When A Form Opens

Feb 11, 2015

I'm trying to add data about a form to a table when the On_Current event fires. The data I want to add is:
windows login username

date and time the On_Current event occurred
name of the form that was opened
that the form was opened
the number of the record (ID) in the table the form is based on

I have the following code

Private Sub Form_Current()
If Me.NewRecord Then
Call FlimOpen("OR IR No", "OPENED")
Else
Call FlimOpen("OR IR No", "OPENED")

[Code] ....

Excuse the use of 'FlimOpen' but I needed a unique word that I would remember (inspired by FlimFlam the cat on the children's channel CBeebies here in the UK)

I try to compile and I get an error about the wrong number of arguments or invalid property assignment. However, the event does fire correctly when I open the form or move from one record to another so something's working!

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved