473,774 Members | 2,248 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DoCmd.OpenForm Problem

I am trying to open a search results form based on the input from a
prompt form. I am using the following code:

--- Begin Code ---
Private Sub btnSearch_Click ()
'Dim Variable and assign data
Dim srce As String, fstnme As String, lstnme As String, bidnum As String
srce = Me.Source_Contr ol

If Not IsNull(Me.Text1 8) Then
lstnme = Me.Text18
'Open Results Form
DoCmd.OpenForm "frmSearch_Resu lts", , , "[last_name] = '" & lstnme & "'"
'Assign Source Control Data
Forms![frmSearch_Resul ts].[Source_Control] = srce
'Close Search Form
DoCmd.Close acForm, "frmCustomer_Se arch", acSaveNo
Exit Sub

ElseIf Not IsNull(Me.Text1 6) Then
fstnme = Me.Text16
'Open Results Form
DoCmd.OpenForm "frmSearch_Resu lts", , , "[first_name] = '" & fstnme &"'"
'Assign Source Control Data
Forms![frmSearch_Resul ts].[Source_Control] = srce
'Close Search Form
DoCmd.Close acForm, "frmCustomer_Se arch", acSaveNo
Exit Sub

ElseIf Not IsNull(Me.Text2 0) Then
bidnum = Me.Text20
'Open Results Form
DoCmd.OpenForm "frmSearch_Resu lts", , , "[last_bidder_num ber] = " &
bidnum 'Assign Source Control Data
Forms![frmSearch_Resul ts].[Source_Control] = srce
'Close Search Form
DoCmd.Close acForm, "frmCustomer_Se arch", acSaveNo
Exit Sub
End If

End Sub

--- End Code ---

Sorry for the word wrapping. All the lines are single lines no wraping
in the program.

The primary search field is the last name. This is why it is checked
first. The problem is when I open the search results form, it opens with
the previous query results not the current request, unless I set a break
point and the code pauses and I then hit the 'RUN' key (F5) to contine
the code execution.

How can I get the form to open with the correct results without stopping
or pausing the code run?

I am using MS-Access 2003 as a front end to a MS-SQL MSDE backend. This
is an Access Project.

Thansk for any help!!

Mike Charney
Nov 13 '05 #1
2 6864
It sounds as if your Results form is not getting properly closed when you
are finished with it.
If there's no other obvious place to close it, you could do this just before
you re-open it.

"Mike" <me@you.com> wrote in message
news:II******** *******@newssvr 17.news.prodigy .com...
I am trying to open a search results form based on the input from a
prompt form. I am using the following code:

--- Begin Code ---
Private Sub btnSearch_Click ()
'Dim Variable and assign data
Dim srce As String, fstnme As String, lstnme As String, bidnum As String
srce = Me.Source_Contr ol

If Not IsNull(Me.Text1 8) Then
lstnme = Me.Text18
'Open Results Form
DoCmd.OpenForm "frmSearch_Resu lts", , , "[last_name] = '" & lstnme & "'"
'Assign Source Control Data
Forms![frmSearch_Resul ts].[Source_Control] = srce
'Close Search Form
DoCmd.Close acForm, "frmCustomer_Se arch", acSaveNo
Exit Sub

ElseIf Not IsNull(Me.Text1 6) Then
fstnme = Me.Text16
'Open Results Form
DoCmd.OpenForm "frmSearch_Resu lts", , , "[first_name] = '" & fstnme &"'"
'Assign Source Control Data
Forms![frmSearch_Resul ts].[Source_Control] = srce
'Close Search Form
DoCmd.Close acForm, "frmCustomer_Se arch", acSaveNo
Exit Sub

ElseIf Not IsNull(Me.Text2 0) Then
bidnum = Me.Text20
'Open Results Form
DoCmd.OpenForm "frmSearch_Resu lts", , , "[last_bidder_num ber] = " &
bidnum 'Assign Source Control Data
Forms![frmSearch_Resul ts].[Source_Control] = srce
'Close Search Form
DoCmd.Close acForm, "frmCustomer_Se arch", acSaveNo
Exit Sub
End If

End Sub

--- End Code ---

Sorry for the word wrapping. All the lines are single lines no wraping
in the program.

The primary search field is the last name. This is why it is checked
first. The problem is when I open the search results form, it opens with
the previous query results not the current request, unless I set a break
point and the code pauses and I then hit the 'RUN' key (F5) to contine
the code execution.

How can I get the form to open with the correct results without stopping
or pausing the code run?

I am using MS-Access 2003 as a front end to a MS-SQL MSDE backend. This
is an Access Project.

Thansk for any help!!

Mike Charney

Nov 13 '05 #2
Something that might help you.

You'll probably have to modify this but your problem is somewhat
similar to a situation I have where I
want to open forms from another form and may :
only want a subset of the data
want the data in a particular sequence
and want to open the form with a particular record showing

My circumstances are different to yours in that I always use convoluted
keys for records (I.e. Ids) not lastname, firstName etc and I always
know the key of the record I want showing

I open the form I want and pass in Openargs on the open statement 3
pieces of information; key field value ^ criteria and sequence

eg 267^"Where City = 'Adelaide' Order by lastName"

The on open event on the called form calls a function which appears
below that parses this info from the openargs parameter (openargs can
only be 1 string value - thats why the data I want is all concantenated
as shown).

It gets the key Value, the where clause and orderby clause (if they
exist) and applies them to the form's filter and orderby properties
then does a find on the form's recordset clone for the key value and
positions the form's recordset to the key using the bookmark property.

The ApplyOpenArgs function requires 2 pieces of data - frm = pointer to
the form calling it (i.e. Me) and the name of the keyfield that the
passed keyvalue applies to. This is where you may need to change it a
bit to maybe pass this from the calling form also, as you seem to be
using different keys depending on circumstances where as I'm always
passing the primary key value of the table the form is displaying.

Also - I have modified the code from something that is more complicated
than I have described - I think it should work but is possible there
will be errors if you just copy it.

Calling Form code:

DoCmd.OpenForm "formyouwanttoO pen", acNormal, , , acFormEdit, , _
& KeyValue & "^" & strCriteria & " " & strSequence

Called form code:
=============== =============== =============== ==========
Private Sub Form_Open(Cance l As Integer)

If ApplyOpenArgs(M e, "[BPAId]") = False Then
MsgBox "Error in applying Filter or Orderby on opening of this
form", vbOKOnly
End If

End Sub

'************** *************** *************** *************** *************** **********
Function ApplyOpenArgs(f rm As Form, strKeyFldName As String) As Boolean
'************** *************** *************** *************** *************** **********

On Error GoTo Err_ApplyOpenAr gs

Dim strCrit As String
Dim strFilter As String
Dim strOrder As String
Dim j As Integer
Dim varKeyValue As Variant
Dim i As Integer

varKeyValue = 0
strCrit = ""
ApplyOpenArgs = True
frm.OrderBy = ""
frm.OrderByOn = False

If Not (Nz(frm.OpenArg s)) = "" Then
j = InStr(1, frm.OpenArgs, "^")
If j = 0 Then
j = Len(frm.OpenArg s) + 1
strCrit = ""
Else
strCrit = Trim(Right(frm. OpenArgs, Len(frm.OpenArg s) - j))
End If
varKeyValue = Mid(frm.OpenArg s, 1, j - 1)

j = InStr(1, strCrit, "ORDER BY")
If j = 0 Then
strFilter = Replace(strCrit , "WHERE ", "")
strOrder = ""
Else
strFilter = Replace(left(st rCrit, j - 1), "WHERE ", "")
strOrder = Right(strCrit, Len(strCrit) - (j + 8))
End If
If Trim(strFilter) <> "" Then
DoCmd.ApplyFilt er , strFilter
End If
frm.OrderByOn = True
frm.OrderBy = Replace(strOrde r, ";", "")
End If

Call frm.RecordsetCl one.FindFirst(s trKeyFldName & " = " & varKey)
frm.Bookmark = frm.RecordsetCl one.Bookmark

Exit_ApplyOpenA rgs:
Exit Function

Err_ApplyOpenAr gs:
MsgBox Err.Description
ApplyOpenArgs = False
Resume Exit_ApplyOpenA rgs

End Function

Nov 13 '05 #3

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

Similar topics

6
4200
by: beowulfs | last post by:
Here's what I've got: I've got a form with combo boxes. you can select already existing company names or type in new ones. if you type in a new one, it prompts you to double click the combo box if you want to add a new company. when you double click it brings up the new company form so you can enter the rest of the information besides just the name there. This all works. Here's what I want:
3
4520
by: Lyn | last post by:
Hi, I have a Search input form which collects from the user a person's name. I am using LIKE with a "%" suffix in the SQL so that the user does not have to type in the full name. When they hit the Search button, a query is run to search the Person table for a match. This produces a recordset (I am using ADO). If the RecordCount is zero, they get a No Match message. If the RecordCount is 1, a DoCmd.OpenForm is performed to open the...
2
3412
by: cannen | last post by:
I am wanting to use Docmd to open another form and set the newly opened forms detail.visible = false to true. stDocName = "frmVacRequest" DoCmd.OpenForm stDocName, acNormal 'This opens my form with out problem but I am unable to set that forms detail property to become visible. I have reasons that I don't want it visible but I prefer not to go into those at this time. Any help would be welcomed truely.
15
3896
by: Thelma Lubkin | last post by:
formA determines some_where and some_value and issues docmd.close ,Me docmd.openform "formB", , ,some_where, , ,some_value formB receives the correct some_where and some_value After completing its work formB issues docmd.close ,Me docmd.openform "formA"
8
13213
by: John Welch | last post by:
I have a command button with the following code: DoCmd.OpenForm "frmSearchAssignments", , , "SearchAssignmentID = 1" (SearchAssignmentID is the PK, auto number) When it runs, the form opens but shows all records, rather than going to the one I want. If I look at the form in design view, it shows 'SearchAssignmentID=1' (without quotes) as the filter in the properties list. frmSearchAssignments is bound to a query qrySearchAssignments....
9
3522
by: keliie | last post by:
Hello (from Access novice), I'm building a switchboard form (using a Treeview object). The treeview is populated by two tables (tblSwitchboardParent and tblSwitchboardChild). Within tblSwitchboardChild, I have a string field called ChildArgument that contains string text of VBA code (e.g., DoCmd.OpenForm "myForm"). When users click on various portions of the Treeview object I want the Tree to either expand or open the report / form.
2
12873
by: mark mestrom | last post by:
hi, i have this problem with OpenForm and the stLinkCriteria. I have the following code: Private Sub Knop22_Click() On Error GoTo Err_Knop22_Click Dim stDocName As String Dim stLinkCriteria As String stDocName = "ALAHistorieEdit"
1
5001
by: RAG2007 | last post by:
Hi all, Have a question I can't get around. I've done this before and for some reason can't get it to work this time. I'm opening a form through docmd.openform, and trying to get it to open an blank form to allow me to add a new record. Problem is, every time I run the method, it opens up the first record in the database, rather than give me a new emtpy record. Please help!!!! I'm using: DoCmd.OpenForm "frmComm", acNormal, , ,...
1
2718
by: silen | last post by:
i am using Access2000. Currently i had a main form call "frmDownload" and sub form "fsubAdmmission". Under the fsubAdmmission, i do have another sub form "fsubHospital". Once i link my application to database A, when "frmDownload" loaded, it does successfully create "fsubAdmmission" object and i am able to assign "fsubAdmmission.form.recordsource". Once i link my application to database B, when "frmDownload" loaded, it failed to assign...
0
9621
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
9454
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
10106
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
10040
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,...
1
7463
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...
0
5355
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5484
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3611
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2852
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.