Hello all,
I have a Combo Box on a form with selection of a firm list. When the
users select a firm from the Combo Box and if the firm has branch(es),
a list of branch(es) of the firm opens in a Datasheet form; if without
branch, a message will prompt if they want to add a branch. If a firm
the users looking for is not on the list, they can type it on the Combo
Box and it will be added on the firm table, then a message will prompt
if they want to add a branch. If yes, then open a form to add branch
and rep, if not close the form.
I have 2 Event Procedures, 1 for "On Not in List" and 1 for "On Click"
as below, but I have error when select a firm with branch: (Run-time
error '2450':
Microsoft Access can't find the form 'frmBranch' referred to in a macro
expression or Visual Basic code.) It seems it couldn't recognize the
RecordsetClone.RecordCount, because if I just open the form without any
If statement, it works. Also if I have the same Procedure on the
Branch form OnOpen, it works too. However, I need the If Statement on
the OnClick (or somewhere else if more appropriate) because I don't
want the form to be open in different circumstance as I state above.
Could someone help me out on this? Your help is greatly appreciated.
Thanks in advance!
******
Private Sub Combo0_Click()
Dim stlinkcriteria As String
stlinkcriteria = "[FirmID]=" & Me![Combo0]
If Forms!frmBranch.RecordsetClone.RecordCount >= 1 Then
DoCmd.OpenForm "frmBranch", acFormDS, , stlinkcriteria
Else
If MsgBox("There is No Branch. Do you want to Add now?", vbYesNo +
vbQuestion) = vbNo Then
Cancel = True
Else
DoCmd.OpenForm "Branch subform", , , , acFormAdd
End If
End If
End Sub
Private Sub Combo0_NotInList(NewData As String, Response As Integer)
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim msg As String
Dim ID As String
Dim stlinkcriteria As String
stlinkcriteria = "[FirmID]=" & Me![Combo0]
ID = Me![Combo0]
On Error GoTo err_combo0_notinlist
If NewData = "" Then Exit Sub
msg = "'" & NewData & "' is not in the list." & vbCr & vbCr
msg = msg & "Do you want to add it?"
If MsgBox(msg, vbQuestion + vbYesNo) = vbNo Then
Response = acDataErrContinue
MsgBox "Please try again."
Else
Set db = CurrentDb
Set rs = db.OpenRecordset("Firm", dbOpenDynaset)
rs.AddNew
rs![FirmName] = NewData
rs.Update
'Prompt to add Branch after add the FirmName
If MsgBox("Firm Has Been Added. Do You Want To Add BRANCH?",
vbYesNo + vbQuestion) = vbNo Then
Cancel = True
DoCmd.Close acForm, "frmEnterFirm"
Else
DoCmd.Close acForm, "frmBranch"
'DoCmd.OpenForm ("frmInputFirmInfo"), , , "[FirmID]= '" & ID &
"'"
DoCmd.OpenForm ("frmInputFirmInfo"), , , stlinkcriteria
End If
Response = acDataErrAdded
End If
exit_combo0_notinlist:
Exit Sub
err_combo0_notinlist:
MsgBox Err.Description
Response = acDataErrContinue
End Sub
****** 1 3265
Orchid wrote:
Hello all,
I have a Combo Box on a form with selection of a firm list. When the
users select a firm from the Combo Box and if the firm has branch(es),
a list of branch(es) of the firm opens in a Datasheet form; if without
branch, a message will prompt if they want to add a branch. If a firm
the users looking for is not on the list, they can type it on the Combo
Box and it will be added on the firm table, then a message will prompt
if they want to add a branch. If yes, then open a form to add branch
and rep, if not close the form.
I have 2 Event Procedures, 1 for "On Not in List" and 1 for "On Click"
as below, but I have error when select a firm with branch: (Run-time
error '2450':
Microsoft Access can't find the form 'frmBranch' referred to in a macro
expression or Visual Basic code.) It seems it couldn't recognize the
RecordsetClone.RecordCount, because if I just open the form without any
If statement, it works. Also if I have the same Procedure on the
Branch form OnOpen, it works too. However, I need the If Statement on
the OnClick (or somewhere else if more appropriate) because I don't
want the form to be open in different circumstance as I state above.
Could someone help me out on this? Your help is greatly appreciated.
Thanks in advance!
******
Private Sub Combo0_Click()
Dim stlinkcriteria As String
stlinkcriteria = "[FirmID]=" & Me![Combo0]
If Forms!frmBranch.RecordsetClone.RecordCount >= 1 Then
DoCmd.OpenForm "frmBranch", acFormDS, , stlinkcriteria
Else
If MsgBox("There is No Branch. Do you want to Add now?", vbYesNo +
vbQuestion) = vbNo Then
Cancel = True
Else
DoCmd.OpenForm "Branch subform", , , , acFormAdd
End If
End If
End Sub
Private Sub Combo0_NotInList(NewData As String, Response As Integer)
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim msg As String
Dim ID As String
Dim stlinkcriteria As String
stlinkcriteria = "[FirmID]=" & Me![Combo0]
ID = Me![Combo0]
On Error GoTo err_combo0_notinlist
If NewData = "" Then Exit Sub
msg = "'" & NewData & "' is not in the list." & vbCr & vbCr
msg = msg & "Do you want to add it?"
If MsgBox(msg, vbQuestion + vbYesNo) = vbNo Then
Response = acDataErrContinue
MsgBox "Please try again."
Else
Set db = CurrentDb
Set rs = db.OpenRecordset("Firm", dbOpenDynaset)
rs.AddNew
rs![FirmName] = NewData
rs.Update
'Prompt to add Branch after add the FirmName
If MsgBox("Firm Has Been Added. Do You Want To Add BRANCH?",
vbYesNo + vbQuestion) = vbNo Then
Cancel = True
DoCmd.Close acForm, "frmEnterFirm"
Else
DoCmd.Close acForm, "frmBranch"
'DoCmd.OpenForm ("frmInputFirmInfo"), , , "[FirmID]= '" & ID &
"'"
DoCmd.OpenForm ("frmInputFirmInfo"), , , stlinkcriteria
End If
Response = acDataErrAdded
End If
exit_combo0_notinlist:
Exit Sub
err_combo0_notinlist:
MsgBox Err.Description
Response = acDataErrContinue
End Sub
******
The problem is that you are referring to frmBranch from your 'firm'
form when frmBranch is not open. You cannot refer to a form's
recordset property as you do in your combo0 click event without it
first being open. You'll need some other way to see if you have branch
records for the selected firm, either by keeping frmBranch always open
(as a subform perhaps, or hidden) or by using dcount() or by using
currentdb.openrecordset("select ... where FirmID = " &
Me![Combo0]).recordcount or some other method...
Hope this helps,
Bruce This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Anthony Kroes |
last post by:
I have a subform on a form and they are not linked. On the main form is
a text box where the user types in a number. When that number changes,
I have some code to make the corresponding text...
|
by: Ian Bailey |
last post by:
I have developed a routine that opens a number of forms with each form
being positioned on a particular record. I am using the
Recordsetclone to find the record and then setting the form bookmark...
|
by: GGerard |
last post by:
Hello
I am trying to refer in code to the RecordsetClone of a subform datasheet
but I'm getting syntax errors.
This is what I am writing:
Set MyDB = DBEngine.Workspaces(0).Databases(0)...
|
by: Br |
last post by:
In an Access2000 project (ADP) I have a form whose recordsource is a
stored procedure in SQL. On the OnOpen event I run a simple piece of
code to move to a record based on a value on another...
|
by: Br |
last post by:
First issue:
When using ADPs you no longer have the ability to issue a me.refresh to
save the current record on a form (the me.refresh does a requery in an
ADP).
We usually do this before...
|
by: G Gerard |
last post by:
Hello
Can I write an SQL statement in code using a RecordSetClone of an open form?
something like:
MySQL = "UPDATE Me!Child0.Form.RecordSetClone SET
Me!Child0.Form.RecordSetClone.MyField =...
|
by: d.francis |
last post by:
I have converted an Access 97 database to Access 2003
The following code now fails and returns Run-time error '3420'
Dim rst as DAO.recordset
Set rst = Forms!frm1!frm2.Form.RecordsetClone
I...
|
by: Certys |
last post by:
Hello,
I have a form where I only allow new records to be added. I enable
this by setting the form property "Data Entry" to Yes.
I want to access other records in the same table- to autofill...
|
by: nspader |
last post by:
Hello All,
I have developed a program to automatically generate and send reports based on certain criteria.
I have realized that there is a problem with its navigation. I will post the code...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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: 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
|
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...
| |