Hi all,
New to access and need some help. I have a form with two fields on it. TxtStateName and TxtState. I neeed to write an if statement if either one IsNull. Such as:
If IsNull (TxtState) then
msgbox "Need to add State" vbOK
SetFocus back on txt box TxtState
Else continue on ?????
I need this for both txtboxes on the form and has to fire before the before update event, actually it could be wrote in with that code if possible. See Below - Private Sub Form_BeforeUpdate(Cancel As Integer)
-
Dim SN As String
-
Dim ST As String
-
Dim stLinkCriteria As String
-
Dim rsc As DAO.Recordset
-
Dim SNkey As Long
-
Dim STkey As Long
-
Dim TGTkey As Long
-
If eMode = True Then
-
eMode = False
-
Exit Sub
-
End If
-
Set rsc = Me.RecordsetClone
-
-
SN = Me.TxtStateName
-
ST = Me.TxtState
-
SNkey = Nz(DLookup("StateID", "Tbl_State", "StateName=" & "'" & SN & "'"), 0)
-
STkey = Nz(DLookup("StateID", "Tbl_State", "State=" & "'" & ST & "'"), 0)
-
-
'Neither exist, add record
-
If SNkey = 0 And STkey = 0 Then
-
Exit Sub
-
End If
-
-
'both exist and are in same existing record, get that record
-
If SNkey > 0 And SNkey = STkey Then
-
TGTkey = SNkey
-
Me.Undo
-
'Cancel = True
-
MsgBox "Warning! State of " _
-
& SN & " and the State Abrev " & ST & " are already in Database." _
-
& vbCr & vbCr & "You will now been taken to the record.", _
-
vbInformation, "Duplicate Information"
-
Call GetRecordToEdit(TGTkey)
-
Call CmdEdit_Click
-
Exit Sub
-
End If
-
-
'SN exists but ST does not, get the SN record
-
If SNkey > 0 And STkey = 0 Then
-
MsgBox StateName & " exists, but " & State & " does not. I will show you the State Name record.", _
-
vbInformation + vbOKOnly, " A T T E N T I O N "
-
Me.Undo
-
Call GetRecordToEdit(SNkey)
-
Call CmdEdit_Click
-
Exit Sub
-
End If
-
-
'ST exists but SN does not, get the ST record
-
If STkey > 0 And SNkey = 0 Then
-
MsgBox State & " exists, but " & StateName & " does not. I will show you the State record.", _
-
vbInformation + vbOKOnly, " A T T E N T I O N "
-
Me.Undo
-
Call GetRecordToEdit(STkey)
-
Call CmdEdit_Click
-
Exit Sub
-
End If
-
-
'both SN and ST exist but not in same record, inform user and get out
-
If SNkey > 0 And STkey > 0 And (SNkey <> STkey) Then
-
MsgBox Me.State & " and " & Me.StateName & " is an invalid pair.", vbCritical + vbOKOnly, " I N V A L I D I N P U T "
-
Me.Undo
-
Exit Sub
-
End If
-
End Sub
2 1878 NeoPa 32,556
Expert Mod 16PB
It's good that you've included your code, but expecting people to work out what your question is - or rather should be - by their reading and interpreting your non-working code is not so good.
Why don't you take a step back and put your actual question into clear English so that we have enough understanding of what you need and can help you without wasting inordinate amounts of time trying to guess what that is.
I can see you're a new member, but bear in mind there are threads at the top of the forum that explain what is expected as a minimum when asking for help.
D9pierce,
Wecome to Bytes!
Another (bot more complicated) approach is to highlight the labels that require entry. Whenever one moves to a different record (using the OnCurrent event), highlight all the required fields. as the user enters data into these fields, if the data is valid, the highlight goes away. If the data entry is not valid, set the focus to the control the user just updated.
But, as NeoPa stated, it's a bit difficult ot understand exactly what your code is trying to do. My first question would be, "Why must the user enter the State and the State Name?" If these items are both from the same table, entering one (or simply selecting one from a combo box) would be sufficient.
The bottom line is that we really need some clarifying information before we can provide more thorough advice.
Thanks.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: gattaca8 |
last post by:
The following script works fine in IE...but gives me a "sBox has no
properties" error in Firefox. sBox is only used in the below method.
function addTop (sectId) {
sBox =...
|
by: GMKS |
last post by:
Hello all,
I have 13 check boxes on a form.
I am trying to check all the check boxes to determine if they are true or false when I close the form.
At present only the first IF...Then...Else...
|
by: misscrf |
last post by:
I have a search form that is great. I have modified it in such a way,
that when search results come up I can bring it back to a useful spot,
say an entry form or a report.
Here is my lemon (...
|
by: Lee-Anne Waters via AccessMonster.com |
last post by:
hi,
hopefully an easy one for someone.
how do i specify two sets of critera in an if statement
for example
if isnull(me.txt27) and me.txtfld = "4" then
|
by: Amy |
last post by:
Hi,
I have 6 If Then Else statements I was supposed to write. I did so but I
know that they have to be wrong because they all look the same. Could
someone take a look at them and point me in the...
|
by: brynne |
last post by:
Can someone give some advice? I am not big on VB scripts, so am trying to write an expression in an update query that is designed to populate a field which I will use as the email first letter. If...
|
by: justbailey |
last post by:
I am very new and bad at programming and taking a vb.net class. I am trying to troubleshoot my code to see why it is not running properly. I found a thread in another forum that said I could not...
|
by: Stefanos Efthimiou |
last post by:
Hi!
I need assistance on the following scenario. I want to have a DB Grid where a user can click on and select from a drop down menu and then see the details of the product automatically filling...
|
by: hrstissiaopai |
last post by:
One very important part of almost all computer languages are conditional statements, and specifically if/else statements. Here is an example.
if(16==16){
window.alert("Yes, 16 does equal 16!...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
| | |