473,785 Members | 2,714 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problems with combo box and data entry form

Access 97SR2-I am trying to create a Job Position data entry form
based on a table. The form has 15 fields on it. I want to use a
combo box to look in the table and see if the position number already
exists. If the position exists, then pull up that record and display
the information on the form. If the position doesn't exist, inform
the user and ask if they want to add it. If they elect to add it,
then have a new record to add it in to. My form has Save, Delete,
Clear, and Close buttons. I have tried having my combo box both bound
and unbound but have not been able to get everything to work yet.

Current errors/problems:

-I am getting a "Run-time error 2105: You can't go to the specified
record. You may be at the end of a recordset." on the code
"Me.Bookmar k = rst.Bookmark 'RecordsetClone .Bookmark" when I try to
look up a record on an existing 'Position Number'.
-Sometimes my existing records (in the table) are getting overwritten
Here is my current code:
Private Sub cmdCloseForm_Cl ick()
DoCmd.Close
End Sub

Private Sub cmdSaveRecord_C lick()
blnSave = -1
DoCmd.RunComman d acCmdSaveRecord
blnSave = 0
End Sub

Private Sub cmdDelete_Click ()
DoCmd.DoMenuIte m acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuIte m acFormBar, acEditMenu, 6, , acMenuVer70
End Sub

Private Sub cmdClear_Click( )
If Me.Dirty Then 'Undo changes only if record is dirty
DoCmd.RunComman d acCmdUndo
End If
ClearCtrls Me 'function to clear all fields and avoid confusing
user

Me.cboPositionN umber.SetFocus
cboPositionNumb er.Value = ""
End Sub

Private Sub Form_BeforeUpda te(Cancel As Integer)
If Not blnSave Then
Cancel = True
DoCmd.RunComman d acCmdUndo
End If
End Sub

Private Sub Form_Current()
blnSave = False
End Sub
Private Sub Form_Error(Data Err As Integer, Response As Integer)
If DataErr = 2169 Then Response = acDataErrContin ue
End Sub

Private Sub Form_Load()
ClearCtrls Me
End Sub

Sub cboPositionNumb er_AfterUpdate( )
' Find the record that matches the control.
Dim rst As Recordset, strTemp As String
Set rst = Me.RecordsetClo ne
rst.FindFirst "[PositionNumber] = '" & Me![cboPositionNumb er] & "'"
If rst.NoMatch Then ' New value
strTemp = Me![cboPositionNumb er]
If MsgBox(strTemp & " does not exist. Do you want to add it?",
vbYesNo) = vbYes Then
rst.AddNew
rst![PositionNumber] = strTemp
rst.Update
rst.Bookmark = rst.LastModifie d
Else
Me.Undo
DoCmd.GoToRecor d , , acFirst
End If
Else ' Existing value
Me.Bookmark = rst.Bookmark 'RecordsetClone .Bookmark
End If
rst.Close
End Sub
Any assistance and/or suggestions on this would be greatly
appreciated.
Thanks,
Alex
Nov 12 '05 #1
1 2875
Al***********@n cmail.net (Alex Wisnoski) wrote in message news:<5c******* *************** ****@posting.go ogle.com>...
Access 97SR2-I am trying to create a Job Position data entry form
based on a table. The form has 15 fields on it. I want to use a
combo box to look in the table and see if the position number already
exists. If the position exists, then pull up that record and display
the information on the form. If the position doesn't exist, inform
the user and ask if they want to add it. If they elect to add it,
then have a new record to add it in to. My form has Save, Delete,
Clear, and Close buttons. I have tried having my combo box both bound
and unbound but have not been able to get everything to work yet.


Try this:

Private Sub Reason_NotInLis t(NewData As String, Response As Integer)
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strMsg As String

strMsg = "'" & NewData & "' is not an available AE Name " & vbCrLf
& vbCrLf
strMsg = strMsg & "Do you want to associate the new Name to the
current DLSAF?"
strMsg = strMsg & vbCrLf & vbCrLf & "Click Yes to link or No to
re-type it."

If MsgBox(strMsg, vbQuestion + vbYesNo, "Add new name?") = vbNo
Then
Response = acDataErrContin ue
Else
Set db = CurrentDb
Set rs = db.OpenRecordse t("tblReasons ", dbOpenDynaset)
On Error Resume Next
rs.AddNew
rs!Reason = NewData
rs.Update

If Err Then
MsgBox "An error occurred. Please try again."
Response = acDataErrContin ue
Else
Response = acDataErrAdded
End If
End If

rs.Close
Set rs = Nothing
End Sub

'************ Code Start **********
' This code was originally written by Dev Ashish. ' It is not to be
altered or distributed,' except as part of an application. ' You are
free to use it in any application, ' provided the copyright notice is
left unchanged.'' Code Courtesy of ' Dev Ashish'
Private Sub cbxAEName_NotIn List(NewData As String, Response As
Integer)
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strMsg As String

strMsg = "'" & NewData & "' is not an available AE Name " & vbCrLf
& vbCrLf
strMsg = strMsg & "Do you want to associate the new Name to the
current DLSAF?"
strMsg = strMsg & vbCrLf & vbCrLf & "Click Yes to link or No to
re-type it."

If MsgBox(strMsg, vbQuestion + vbYesNo, "Add new name?") = vbNo
Then
Response = acDataErrContin ue
Else
Set db = CurrentDb
Set rs = db.OpenRecordse t("tblAE", dbOpenDynaset)
On Error Resume Next
rs.AddNew
rs!AEName = NewData
rs.Update

If Err Then
MsgBox "An error occurred. Please try again."
Response = acDataErrContin ue
Else
Response = acDataErrAdded
End If
End If

rs.Close
Set rs = Nothing
Set db = Nothing
End Sub
'*********** Code End **************
from www.mvps.org/Access
Nov 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3209
by: mal | last post by:
Sorry for repost - system added to another subject for some reason Have tried numerous ideas from the group to solve this one. It is such a simple example that it should be straightforward ! I just want to add a new item to a combo that has data from a file, by typing in the new value , adding to the file and the requerying to get the new valus in the list. i.e. a data entry and data display combo box. I select an item from cmb1 and...
1
3368
by: James | last post by:
I am used to VB6 but need to develop something in .Net. I need to create several bound combo-boxes which will use lookup tables to get their values. I created a form using the dataform wizard. As part of the setup, I specified a new dataset, which included the data & lookup tables. I also specified the relationships when required. I then added a combo box control to my form, following the instructions from
2
3576
by: Robert | last post by:
I have a form (frmWorksheet) that contains project information from a Projects table. The form contains a number of fields including ClientID and Project. On the form header is two combo boxes, SelectClient and SelectProject. When a user selects a client from the SelectClient combo, only the projects associated with that client will appear in the SelectProjects combo. If the user wants to add a new project to that list, they can dblclick...
1
1929
by: Wes Brooks | last post by:
Hello expert, Please help me with the following problems. I have spent ages to resolve them but no luck. I have two forms. (1) "Document Reception Input Form" is the main form. The search field Document ID is unbound combo box. The table is Documents. (2) "Document Reception Subform" is the sub form in tabular form. The linked field is DocID. The table is DocumentReception.
2
1445
by: sara | last post by:
I think I don't understand combo boxes and forms - and all that I'm reading is just confusing me more. I am doing a "favor" for a non-profit organization. They take a phone call and need to either 1. See the client record OR 2. Add a new record if the cient isn't in the database. I got this to work if I have a form open just showing the Combo Box (unbound) to select a client, or choose "Add new". Selecting a client
3
3643
by: stumo | last post by:
Hi I'm fairly new to access and as such my experience of VBA is somewhat limited. I have a login form which is linked to an "employees table" which asks for users to enter their name and password. The current VBA performs all the relevant checks around user name & password etc with no problems. However based on the users access level (which is set in the field "strAccess" in the Enployees table) when I click the "Login" button I'd like to...
1
4003
by: Jason Northampton | last post by:
Hello This is the first time I've used a discusion forum and up until now I have managed to use and or modify VB code from the various sites on the web, until now! This is a simple problem and I am trying to update a contact record with FirstName and LastName contained on a table TblContacts via a Combo Box using the Limit to List function to add new contacts and perform a search to check if the contact is new or already exists on the...
30
26535
ADezii
by: ADezii | last post by:
This week’s Tip of the Week will clearly demonstrate how you can dynamically set the Drop Down List Width of a Combo Box to the length of the longest item in its Row Source. The inspiration for this Tip came from one of our own resident Experts, mshmyob. In response to a Thread relating to this very Topic, mshmyob came up with a rather ingenious method to accomplish this task. He computed the Average Character Width of a String consisting of...
4
4126
by: AXESMI59 | last post by:
have a project in which I am entering Serial Numbers and Date codes into a Combo box. Serial numbers are all different. However, they could each have the same Date Code. Each Serial Number has a corresponding Date Code which I then write to a table using VBA. When I try to enter a duplicate date code, it automatically finds the duplicate and will not allow me to add it again to that combo box. How do I configure that combo box so I can enter the...
0
9643
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10319
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10147
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10087
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9947
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7496
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4046
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.