473,386 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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.Bookmark = 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_Click()
DoCmd.Close
End Sub

Private Sub cmdSaveRecord_Click()
blnSave = -1
DoCmd.RunCommand acCmdSaveRecord
blnSave = 0
End Sub

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

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

Me.cboPositionNumber.SetFocus
cboPositionNumber.Value = ""
End Sub

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Not blnSave Then
Cancel = True
DoCmd.RunCommand acCmdUndo
End If
End Sub

Private Sub Form_Current()
blnSave = False
End Sub
Private Sub Form_Error(DataErr As Integer, Response As Integer)
If DataErr = 2169 Then Response = acDataErrContinue
End Sub

Private Sub Form_Load()
ClearCtrls Me
End Sub

Sub cboPositionNumber_AfterUpdate()
' Find the record that matches the control.
Dim rst As Recordset, strTemp As String
Set rst = Me.RecordsetClone
rst.FindFirst "[PositionNumber] = '" & Me![cboPositionNumber] & "'"
If rst.NoMatch Then ' New value
strTemp = Me![cboPositionNumber]
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.LastModified
Else
Me.Undo
DoCmd.GoToRecord , , 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 2855
Al***********@ncmail.net (Alex Wisnoski) wrote in message news:<5c**************************@posting.google. 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_NotInList(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 = acDataErrContinue
Else
Set db = CurrentDb
Set rs = db.OpenRecordset("tblReasons", dbOpenDynaset)
On Error Resume Next
rs.AddNew
rs!Reason = NewData
rs.Update

If Err Then
MsgBox "An error occurred. Please try again."
Response = acDataErrContinue
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_NotInList(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 = acDataErrContinue
Else
Set db = CurrentDb
Set rs = db.OpenRecordset("tblAE", dbOpenDynaset)
On Error Resume Next
rs.AddNew
rs!AEName = NewData
rs.Update

If Err Then
MsgBox "An error occurred. Please try again."
Response = acDataErrContinue
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
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...
1
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....
2
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,...
1
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...
2
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...
3
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...
1
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...
30
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...
4
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
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...

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.