Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 26th, 2009, 09:59 AM
Registered User
 
Join Date: Jun 2009
Posts: 4
Thanks: 3
Thanked 0 Times in 0 Posts
Default Please i need some help it's killing me!

Hello everyone,
I'm trying to open an existing record on a form (frmgood) using a button (findrecord) on different form (frmrecord). The user enter a number on textbox (text1) on frmrecord, and if the number matches the existing record [IDA], frmgood opens on the right existing record. If the text1 doesnt match IDA, a msgbox should appear saying "Enter the right record number" and if the user hit the button (findrecord) without entering a number on text1 a msgBox should appear saying "Please enter a number".

I know its an if statement, however i couldn't make it work. The only thing that works is opening the existing record by using the line code below:

DoCmd.OpenForm "frmgood", acNormal, , "[IDA]=" & Me("text1")

Any help would be really appreciated. I'm a new user, and i'm using Access 2002. Thank you in advance
Reply With Quote
  #2 (permalink)  
Old June 26th, 2009, 12:11 PM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Here is what I usually do for input validation:

Code:
Dim sIDA As String 'I am assuming it is a string
Dim sLink As String
 
If IsNull(Me.IDA) Or Me.IDA = "" Then
   MsgBox "Please enter an IDA.", vbInformation
   Me.IDA.SetFocus
   Exit Sub
Else
   sIDA = Me.IDA
End If
 
sLink = "[IDA] = '" & sIDA & "'"
 
DoCmd.OpenForm "frmgood", acNormal, , sLink
If IDA is a number, then

Code:
Dim lIDA As Long
Dim sLink As String
 
If IsNull(Me.IDA) Or Me.IDA = 0 Then
   MsgBox "Please enter an IDA.", vbInformation
   Me.IDA.SetFocus
   Exit Sub
Else
   lIDA = Me.IDA
End If
 
sLink = "[IDA] = " & lIDA
 
DoCmd.OpenForm "frmgood", acNormal, , sLink
That will check to make sure a number was entered, and then stop the form from opening until they do select a number.

I would use the combo wizard to create a look up combo box on the IDA field, and then have them make a selection from the combo box. That way you know that whatever they choose is a valid selection, at least. Then you won't have to check for Nulls.

Code:
Dim lIDA As Long
Dim sLink As String
 
If Me.cboIDA = 0 Then
   MsgBox "Please enter an IDA.", vbInformation
   Me.cboIDA.SetFocus
   Me.cboIDA.DropDown
   Exit Sub
Else
   lIDA = Me.cboIDA
End If
 
sLink = "[IDA] = " & lIDA
 
DoCmd.OpenForm "frmgood", acNormal, , sLink
Did that help?
__________________
mmcdonal

Look it up at: http://wrox.books24x7.com
Reply With Quote
The Following User Says Thank You to mmcdonal For This Useful Post:
abrahom (June 26th, 2009)
  #3 (permalink)  
Old June 26th, 2009, 12:57 PM
Registered User
 
Join Date: Jun 2009
Posts: 4
Thanks: 3
Thanked 0 Times in 0 Posts
Default Thanks mmcdonal

Private Sub Enter_Click()
Dim lIDA As Long
Dim sLink As String

If IsNull(Me.text1) Or Me.text1 = 0 Then
MsgBox "Please enter a record number.", vbInformation
Me.text1.SetFocus
Exit Sub
Else
lIDA = Me.text1
End If

sLink = "[IDA] = " & lIDA

DoCmd.OpenForm "frmgood", acNormal, , sLink ( here an error 2501 appears, saying "Openform action was canceled)

The if statement work perfectly if i enter 0 or i leave it blank.
I also want to add an if statement to be operated whenever the user enter a number (in text1) that doesnt exist as a record (IDA), or if it exists it will open frmgood at that record number (IDA). I really appreciate your time and help.
Reply With Quote
  #4 (permalink)  
Old June 26th, 2009, 03:24 PM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

That is why I suggested using a bound combo box to the column the user is selecting.

For example, if you run the combo box wizard on the first form, and have it look up values in IDA, and limit it to the list, then your users will ONLY be able to select a valid number. So there is no need to check for the validity of the number.

If you have this situation:

ID IDA
1 1X23
2 2B47
3 9S43

etc, you can still use this method, but you have to point the variable at cboIDA.Column(1) instead.

Will that work for you?
__________________
mmcdonal

Look it up at: http://wrox.books24x7.com
Reply With Quote
The Following User Says Thank You to mmcdonal For This Useful Post:
abrahom (June 26th, 2009)
  #5 (permalink)  
Old June 26th, 2009, 03:59 PM
Registered User
 
Join Date: Jun 2009
Posts: 4
Thanks: 3
Thanked 0 Times in 0 Posts
Default

It works nicely! Good guy. I complicated my life by having a textbox, i dont know what i was thinking. You have been so helpful to me, i really appreciate that.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
javascript started killing flash nairaby HTML Code Clinic 1 August 28th, 2007 11:47 PM
Java is KILLING me!!! I really need help!!!!! ironchef Java Basics 0 October 13th, 2006 09:45 PM
Java is killing me!! Pls Help!!!! il nonno Java Basics 7 September 24th, 2006 10:29 PM
Datareader problem, killing me joer80 ADO.NET 1 March 23rd, 2006 06:44 PM
This is killing me RobCarter VB Databases Basics 1 January 18th, 2006 01:00 PM



All times are GMT -4. The time now is 08:48 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.