General :: Check Or Validate If There Is Record In SQL Statement?

Mar 13, 2014

Payroll main form to post attendance record. Before I open the attendance form, I wanted to check if there is a record in the sql statement.

The code below produces error MS Acces object "Variable or With Block Variable Not Set"

Code:
Private Sub cmdPostAtt_Click()
Dim stSQL As String
Dim dbHBK As DAO.Database

[Code].....

View Replies


ADVERTISEMENT

Validate Check Box

May 5, 2006

I have check box [yes/no] on a form. I want to be able to tick check box only if today is Friday or Saturday. Any ideas please?

View 2 Replies View Related

General :: How To Check The Record Count

Sep 11, 2014

1) If I check recordcount without move rst to last position I get wrong number of recordcount.

Code:

rst = CurrentDb.OpenRecordset(strSQL)
msgbox nz(rst.RecordCount, 0)

2) If I move rst to last position, number of recordcount is correct, but! If there's no record in my string I get an error that rst can't move to last position.

Code:
rst = CurrentDb.OpenRecordset(strSQL)
rst.MoveLast
msgbox nz(rst.RecordCount, 0)

how to check correctly RecordCount even if my query in string has no record?

View 5 Replies View Related

General :: How To Check The Record-count

Apr 3, 2015

1) If I check recordcount without move rst to last position I get wrong number of recordcount.

Code:
rst = CurrentDb.OpenRecordset(strSQL)
msgbox nz(rst.RecordCount, 0)

2) If I move rst to last position, number of recordcount is correct, but! If there's no record in my string I get an error that rst can't move to last position

Code:
rst = CurrentDb.OpenRecordset(strSQL)
rst.MoveLast
msgbox nz(rst.RecordCount, 0)

So the question is, how to check correctly RecordCount even if my query in string has no record?

View 2 Replies View Related

Validate Form Before Navigating To Next Record

Dec 7, 2006

Hi

I was wondering if anybody could help with this. I have searched through this forum and there doesnt seem to be an answer to this.

I have a form that i would like to validate. At present i have put the data validation on the save button which triggers a script that checks to see if certain boxes have been filled in on the form. I can only get this to work be attaching it to the onclick event on a save button, however, what i really want is to be able to ditch the save button (since access writes to the DB as it goes along) and have this script triggered whenever the user tries to navigate to either a new record/ another existing record or close the form

I tried putting this on the beforer update event, but this does not work, additionally tried doing before update event with the code inside an if me.form.dirty = true statement
this did not work either, has anybody got any suggestions

Please see my code below

Thanks

Marcus

Dim sDeliveryto As String
Dim sDeliveryValid As String
Dim sDept As String
Dim sDeptValid As String
Dim sReq As String
Dim sReqValid As String
Dim sReqNo As String
Dim sReqNoValid As String
Dim sReqPoint As String
Dim sReqPointValid As String
Dim sOrderDetailsValid As String
Dim sQuantity1 As String
Dim sQuantity1Valid As String
Dim sDetails1 As String
Dim sDetails1Valid As String
Dim sPrice1 As String
Dim sPrice1Valid As String
Dim sSupplier1 As String
Dim sSupplier1Valid As String
Dim sCostCentre1 As String
Dim sCostCentre1Valid As String
Dim sAccountCode1 As String
Dim sAccountCode1Valid As String
Dim sAuth As String
Dim sAuthValid As String



sDeliveryto = Me.TBDeliveredTo & ""
sDept = Me.TBDept & ""
sReq = Me.tbrequisitioner & ""
sReqNo = Me.TBRequisitionNo & ""
sReqPoint = Me.TBReqPoint & ""
sQuantity1 = Me.TBQ1 & ""
sDetails1 = Me.TBD1 & ""
sPrice1 = Me.tbup1 & ""
sSupplier1 = Me.tbs1 & ""
sCostCentre1 = Me.ccc1 & ""
sAccountCode1 = Me.tbac1 & ""
sAuth = Me.TBAUTH & ""



Select Case sDeliveryto
Case Is = ""
Me.TBDeliveredTo.BackColor = "8421631"

sDeliveryValid = "Invalid"

Cancel = True
Case Else
sDeliveryValid = "valid"
Me.TBDeliveredTo.BackColor = "16777215"

End Select


Select Case sDept
Case Is = ""
Me.TBDept.BackColor = "8421631"

sDeptValid = "Invalid"

Cancel = True
Case Else
sDeptValid = "valid"
Me.TBDept.BackColor = "16777215"

End Select

Select Case sReq
Case Is = ""
Me.tbrequisitioner.BackColor = "8421631"

sReqValid = "Invalid"

Cancel = True
Case Else
sReqValid = "valid"
Me.tbrequisitioner.BackColor = "16777215"

End Select

Select Case sReqNo
Case Is = ""
Me.TBRequisitionNo.BackColor = "8421631"

sReqNoValid = "Invalid"

Cancel = True
Case Else
sReqNoValid = "valid"
Me.TBRequisitionNo.BackColor = "16777215"

End Select

Select Case sReqPoint
Case Is = ""
Me.TBReqPoint.BackColor = "8421631"

sReqPointValid = "Invalid"

Cancel = True
Case Else
sReqPointValid = "valid"
Me.TBReqPoint.BackColor = "16777215"

End Select

If Len(sReqPoint) < 6 Then
sReqPointValid = "Invalid"
Me.TBReqPoint.BackColor = "8421631"
Cancel = True
Me.lblReqPoint.Visible = True

Else
sReqPointValid = "valid"
Me.TBReqPoint.BackColor = "16777215"
Me.lblReqPoint.Visible = False
End If

Select Case sQuantity1
Case Is = ""
Me.TBQ1.BackColor = "8421631"

sQuantity1Valid = "Invalid"

Cancel = True
Case Else
sQuantity1Valid = "valid"
Me.TBQ1.BackColor = "16777215"

End Select


Select Case sDetails1
Case Is = ""
Me.TBD1.BackColor = "8421631"

sDetails1Valid = "Invalid"

Cancel = True
Case Else
sDetails1Valid = "valid"
Me.TBD1.BackColor = "16777215"

End Select


Select Case sPrice1
Case Is = ""
Me.tbup1.BackColor = "8421631"

sPrice1Valid = "Invalid"

Cancel = True
Case Else
sPrice1Valid = "valid"
Me.tbup1.BackColor = "16777215"

End Select

Select Case sSupplier1
Case Is = ""
Me.tbs1.BackColor = "8421631"

sSupplier1Valid = "Invalid"

Cancel = True
Case Else
sSupplier1Valid = "valid"
Me.tbs1.BackColor = "16777215"

End Select

Select Case sCostCentre1
Case Is = ""
Me.ccc1.BackColor = "8421631"

sCostCentre1Valid = "Invalid"

Cancel = True
Case Else
sCostCentre1Valid = "valid"
Me.ccc1.BackColor = "16777215"

End Select


Select Case sAccountCode1
Case Is = ""
Me.tbac1.BackColor = "8421631"

sAccountCode1Valid = "Invalid"

Cancel = True
Case Else
sAccountCode1Valid = "valid"
Me.tbac1.BackColor = "16777215"

End Select

Select Case sAuth
Case Is = ""
Me.TBAUTH.BackColor = "8421631"

sAuthValid = "Invalid"

Cancel = True
Case Else
sAuthValid = "valid"
Me.TBAUTH.BackColor = "16777215"

End Select


' Display message box warning

If sDetails1Valid = "Invalid" Or sQuantity1Valid = "invalid" Or sReqPointValid = "Invalid" Or sReqNoValid = "Invalid" Or sReqValid = "Invalid" Or sDeptValid = "Invalid" Or sDeliveryValid = "Invalid" Or sPrice1Valid = "Invalid" Or sCostCentre1Valid = "Invalid" Or sAccountCode1Valid = "Invalid" Or sAuthValid = "Invalid" Then
MsgBox "Please fill all highlighted fields on the form!!!!!"
Else

DoCmd.Save
MsgBox "Is all the information Correct?", vbOKCancel


'open report

Me.btnClose.Visible = True
Me.btnInvoice.Visible = True
Me.btnDeleteClose.Visible = False




End If

View 3 Replies View Related

Possible To Validate A Single Record In A Field

Aug 19, 2014

I've done some looking into how to validate in Access and I found how to do it for an entire field but I was wondering if it's possible to validate a single record in a field.

View 6 Replies View Related

General :: Validate Headers Of Source Data

Jan 17, 2014

I'm working with several different source datasets. Mostly this are TXT files.

When I import the data in a new table with a specification, I want to validate if the dataset is the correct dataset be validating the headers in the source data.

I have created a table with the headers, that consists of 92 columns. Below 3 example columns of the header data:

tbl_Tickets_Headers
Field1 Field2 Field3
StagnationId TicketTypeId SequenceNr

Now I want to check during the import of the imported data has a line in it that is equal to the data in the table headers. If not, the import stops and informs the user that the data set is not correct. This to prevent that incorrect data will be inserted into the database.

Some extra information: The data is import into the database via VBA DoCmd.TransferText into a new created table, using an inport specification.

If the data is okay, it will be appended to an existing table that is being used to process the data further. After that the import table is being deleted.

View 14 Replies View Related

General :: Check Box Event - Lock Textboxes Depending On Each Record

Aug 30, 2013

I have a checkbox which when checked then turns textboxes to locked as below. However when I navigate to the next record which may not be checked the text boxes remain locked. I obviously want to lock the boxes depending on each record. I am navigating via the windows next/back record buttons. How do i do it?

Private Sub Check44_Click()
If Check44.Value = -1 Then
serial.Locked = True
gain.Locked = True
swst.Locked = True
Else
serial.Locked = True
gain.Locked = True
swst.Locked = True
End If
End Sub

View 6 Replies View Related

General :: Get Latest Record Added Of Item - Check Period Between Now And Date Saved

Sep 28, 2014

In my Access app I need to get the latest record added of an item from a MS Sql table and check the period between now and the date saved in the record.

So my guess is:
Select TOP 1 * from tbl_StockItems
Where StockId = Loc_StockId

I then need to check the days between tbl_StockItems.LastStockDate and Today.

How would I write an Access VBA query to give me the amount of days and put that number into a variable.

View 4 Replies View Related

If Statement To Check For Duplicate Entries With List Box

May 17, 2006

I have a problem where in a table called tblPatientLanguage
that contains three fields

PatientLanguageID
PatientID
LanguageID

a patient who is identified by PatientID can speak several languages
identified by the LanguageID.

The problem is with my current form and code


For Each varSelected In Me!lstLanguage.ItemsSelected
rs.AddNew
rs("PatientID") = [Forms]![frmPatientDemographics]![PatientID]
rs("LanguageID") = Me!lstLanguage.ItemData(varSelected)
rs.Update
Next varSelected



when the user click on the command button called cmdOK it will put the
data in the table "tblPatientLanguage" and corresponding fields. without
checking to see if there is already a duplicate languageID that corresponds to the
same patientID in the table

This has lead to duplicates in the table

example
PatientID = 9

if I look in the table I will see 7 entries that say

PatientID = 9 and LangaugeID = 7

I want to prevent this from happening with and if statement
I could make both the PatientID and LanguageID primary keys
this would prevent this from happening. But I would rather do it in
the VBA code? This way in will move thorugh the selections without poping an error and the person inputing the date. Any ideas sorry for being long winded. I attached the
database.

PS. If looking at the database you have to use form frmPatientDemographics and click on the language link

View 1 Replies View Related

Access VBA Statement To Check For Null Entries

Jan 24, 2012

I've built a form on my Access database that invites a user to enter a start date and an end date into two textboxes. When i press a command button, a parameter query runs which uses the two textboxes as the parameter's criteria. However, to ensure that both textboxes have a data entry, i have tried entering in some VBA that prompts the user to enter in a date if its left null...then set focus to that textbox: Here it is...

If IsNull(Me.txtWeight1) Then MsgBox "You must enter a minimum weight!"
Me.txtWeight1.SetFocus
Else
If IsNull(Me.txtWeight2) Then MsgBox "You must enter a maximum weight!"
Me.txtWeight2.SetFocus
Else
If IsNull(Me.txtWeight1) And IsNull(Me.txtWeight2) Then MsgBox "You must enter a min and max weight!"
End If

This will not compile for me! I've tried with and End If and without an End If and other stuff. Why won't it work?

View 4 Replies View Related

Modules & VBA :: Retrieve / Validate Data On 2nd Form Based On Record Selected On 1st Form

Jul 29, 2013

Can I look up and verify data on a "second" form based on a selected record from first (still open) form.

I am trying to allow users to select a User Name from a combo box list and then open "Change Password" form when they select "Change Password" for that selected user name.

My problem is that I can't figure out how to associate and verify the data tied to the user name selected on the previous (Login) form ( I am trying to validate the old password tied to that selected record).

I have the first login form created, and it's working just fine. I also have the change password form created (and it's displaying the user name selected from the first form using:

Code:
Private Sub Form_Load()
With Forms![frmLogin]![cboUserName]
Me.txtPwdChgUserID = .Column(2, .ListIndex)
End With
EndSub

I also have the code written to validate and confirm old password, new password and validate new password (when the save button is clicked). I have yet to update the password with the new password (still trying to figure that out).

Attached zip file has screen shots of the two forms.

View 3 Replies View Related

Queries :: IIF Statement In Query Criteria Based On Check Box

Jun 19, 2014

I have a form with a check box. A query is run that looks at that check box and decides what the criteria are based on that. So, if the check box is checked, it should pull in all data in the field that is a Y. If it is not checked, i want it to pull all data (Y's and N's and blanks).

here is my criteria:

IIf([Forms]![frm_Query_Form]![CheckBox]<>0,"Y","*")

This does not seem to work. I have also tried:

IIf([Forms]![frm_Query_Form]![CheckBox]<>0,"Y")
IIf([Forms]![frm_Query_Form]![CheckBox]<>0,"Y",Like "*")
IIf([Forms]![frm_Query_Form]![CheckBox]<>0,"Y","like "*"")

View 14 Replies View Related

Forms :: Nested IF Statement To Check If Input Box Is Null On Form

May 9, 2014

I have a form in my Access database that has 3 input boxes by which a user can locate a record by. The problem I am running into is that I can not get a nested IF statement to work properly to first check which of the search boxes are filled in and second search by whichever is filled in. I have come up with the following code that seems to be only searching by the first input box. If the first input box is blank it does not move to the second or third numbers so I imagine there may be something wrong with the order of my IF statement or the syntax is off.

View 14 Replies View Related

Check Data On Leaving A RECORD- Record, Subforms And All

May 24, 2005

I have an application that enters candidates in, who apply for a job.

I found that I can enter a candidate in, and if I dont enter at least an address type or phone type ( giving that candidate an address record, albiet a blank one (just a type of address) and a phone record) then the candidate wont have a sub record for addres or phone at all.

This is hurting my reports. They are set to pull the primary address and phone only, as we dont need to have 2-3 contact information for a candidate on a report This is how I found out that I had blank address and phone for some test records. I need to be able to check when a person does a number of things, that at least the combos for phone type and address type have been chosen as something. This will ensure that they have a primary address and phone, as I have code that takes care of all that. I tried putting the following code in the form's before update, but since it is calling to a subform, the minute I tab TO the address combo, I get the message. The form is updating before I get the chance to skip the field.


Here is the lay out. A user can enter in candidate, their address, phone, application and activities. Address, phone, applications and activities are all sub reports on a tab control. The user should be able to move freely within any record, and only be bothered when they try to leave, if important information is still empty. I dont want to control how they enter ('you must enter this first!' lol) just that they do enter it in the end.

What I want to do is check when the user is leaving a record.(closing form, going to another record, clicking the search button that opens another form etc) if either combo is empty (no primary contact info) then it gives the message and goes back to the combo that is empty.

Here is the code I have. If anyone can help me find the right place to put it, I would really appreciate it. Thank you,



If IsNull(Me.[subAddressEntry].Form![cmbAddressTypeID]) Then
msgbox "You must enter an Address"
Me.[subAddressEntry].Form![cmbAddressTypeID].SetFocus
Cancel = True
ElseIf IsNull(Me.[subPhoneEntry].Form![cmbPhoneTypeID]) Then
msgbox "You must enter a Phone"
Me.[subPhoneEntry].Form![cmbPhoneTypeID].SetFocus
Cancel = True
Else: Cancel = False
End If



If I can't figure this out, I am thinking of making a new address type and phone type. Call it "none chosen" and then make that a default selection. Then one would always be chosen...I think. I would like to avoid that though.

Thanks again.

View 3 Replies View Related

General :: IIF Statement With Message Box

Nov 16, 2012

I am trying to put a message box in an if statement and im struggling.

iif([Voucher]>0 and [VoucherNumber]>0,=MsgBox("Please Bla Bla Bla",vbOK))

I've searched google and 'Tech On The Net' and i still cant figure out why it has an error

the error is Complie Error: Expected Expression

The part hightlighted is the = sign. i remove this and it then doesnt like part of the Message. I don't know what is happening.

View 4 Replies View Related

General :: IIF Statement To Add Value In Next Column

Nov 12, 2013

I am trying to add a value to a column in a query based on the value of another column.

I am using an iif statement for it but can't get it to work. I have a column called [Was Worker Born in UK] which has 3 options of "Yes, "No" and "Unknown". The next column is the [COUNTRYOFBIRTH] column.

I basically want [COUNTRYOFBIRTH] to say "866" if [Was Worker Born in UK] is "Yes".

View 14 Replies View Related

General :: SQL Statement Using A Variable

Feb 25, 2014

Is there a way to use a variable in an SQL statement?

Something like this:

Code:

dim mysql1, newname
newname = inputbox("direction on what to do go here?",,)
mysql1 = "INSERT INTO FinalAll SELECT newname.* FROM newname;"
DoCmd.RunSQL mysql1

Where newname would be a variable assigned from an input box.

I want to populate a single table from several different tables but have the user specify which tables to use.

View 8 Replies View Related

General :: Check Box That Changes Value In Combo Box

Sep 3, 2013

I have a form with a combo box (it has two states (In process / On file)) and a checkbox and I need that when the checkbox is checked, change the status of the combo box..The combobox and checkbox are in different tables (Assigned and Movements, respectively) and refer to different types of data.

The checkbox Refers to a set of tasks FINISHED, then, if that's the case, They must change the values ​​of the ComboBox That has two values ​​or options (In process / On file). Note: These two values ​​are searched fields in a table "Status", and searches for values ​​in a table with the wizard searches

For example: While ComboBox contained in "In Process", the checkbox is unchecked and if this "On File" checkbox is marked.

View 8 Replies View Related

Check Next Record

Nov 18, 2006

I'm sure the coding is very simple, the question is .... can I build an expression using an IIF statement that checks whether the current field is the same as the same field in the next record? If it is put a 1, if not put a 0. Easy in Excel, not sure about Access??

View 2 Replies View Related

Check For Record

May 17, 2005

Hi Everyone

i would like to check a record exits before a new entry is saved. However i would like to check on three criterias and i am not sure on how to write the if statement.

IF Dcount "CompanyName" & "FirstName" & "Last Name" from "tblcustomer" is the same as "frmCompanyName" & "frmFirstName" & "frmLastName" > 0

Then

Msgbox "This Customer Already Exists"
Cancel = True
frmcompanyname.setfocus

End IF

Could someone please translate it into the correct code?

Many Thanks

View 4 Replies View Related

Record Check!

Oct 25, 2006

I am running a check for checking whether a value already exists in the database table. But the problem is that the control passes right through this check.

It does not give an error too...

If txt_id.Value = DLookup("id", "indicateur", "id=" & txt_id.Value) Then
info = MsgBox("Cette 'Id' déjà existe !", vbInformation)

whats wrong with this 'IF' loop??

View 8 Replies View Related

Select Case Statement - General Q

Feb 6, 2008

If I write a select case statement for a field X i.e. 6 to 7 for example will this:1. Select any fields X where the number is greater than or equal to 6 but less than (and not including) 7B. Select any fields X where the number is greater than or equal to 6 but includes decimels of 7 i.e. 7.5 ORC. Select any fields X where the number is greater than or equal to 6 but includes but literally only includes cases where the the whole number 7 appears>I only ask because in an example in a book I am looking at says:Case 10000 to 20000......Case 20001 to 30000I would have through the word "to" means until but not including but in this case the field that equals 20000 would never be selected?

View 14 Replies View Related

General :: If Statement Comparing To Fields

Sep 27, 2012

query is refering to 2 tables

Table_1 with below column
Mode
6
6
6
6
6
4
4

Table_2 with below column

Type
06
GL
PL
04
16

Both tables are joined, and the pseudo code i'm trying to get to work is;

if table_1.mode = 6 and table_2.type = 06 , then "MATCH" , else "NO_MATCH"

I have tried below, but doesn't work.

Expr1: IIf(IsNumeric([TABLE_2]![TYPE])="06" And IsNumeric([TABLE_1]![MODE])=6,"MATCH","NO_MATCH") , returns incorrect results.

Ideally would like this

if table_1.mode = 6 and table_2.type = 06 , then "MATCH" , else "NO_MATCH"

or

if table_1.mode = 4 and table_2.type = 04 , then "MATCH" , else "NO_MATCH

View 6 Replies View Related

General :: Select Statement On Form

Aug 23, 2012

using the Select statement on a form;I have it looking up 3 fields, Ordered by the first and bound by the first.the other 2 are being stored in different fields.What is weird is that I need to have the first field entered twice in order for it to show up, which means I'm looking up 4 fields.When I go to store the selection after, only 2 are available... know this confusing; here is the Select Statement;

SELECT [ITEM CODE1].[ItemCode],[ItemCode],[Customer],[Project Description] FROM [ITEM CODE1] ORDER BY [ITEM CODE1].[ItemCode] ;

If I don't type ItemCode twice, it shows Project Description in the drop down box. When I use the code above, only ItemCode and Customer are available to store in other fields;

Me.Customer = Me.ComID.Column(2) which actually stores Customer (should be column 3)

Column(3) and Column(4) won't do anything.

View 3 Replies View Related

If, Else Statement With Current Record

Nov 21, 2006

I started a thread on this yesterday, but realised I was some way off achieving what I want, so am starting a new thread.

Have attached copy of my db. What I want to achieve is this: From frmLayClientDetails click on the cmd button See invoice details, then click on the cmd button Preview this invoice. I want to see just the invoice for the current record – easy enough for most, and I have seen code for this elsewhere in the forum. However, clients have different invoicing addresses, depending whether they are dealt with directly (Private) or via another consultancy, hence I have two invoice layouts (OK, I’m sure there is a way of getting around this as well). So as the db is at the moment, I need to say “If the SolicitorID is 1, then open rptInvoicePrivateClients, Else open rptInvoiceLocumWork”

Can someone help me with this please?
Thanks in anticipation.

View 7 Replies View Related







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