473,396 Members | 2,099 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,396 software developers and data experts.

{SOLVED} Go to Selected Record in a another form.

Hi All,
I have a cmd button "Details" on a form listing all available records; how do I direct it to the selected record rather than just open a form?
Below is the code for Open the form I have so far. Thanks for the help!
maili
================================
Private Sub cmdDetails_Click()
On Error GoTo Err_cmdDetails_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "PromosMainForm"

stLinkCriteria = "[PromoCode]=" & Me![PromoCode]
DoCmd.OpenForm stDocName, , stLinkCriteria

Exit_cmdDetails_Click:
Exit Sub

Err_cmdDetails_Click:
MsgBox Err.Description
Resume Exit_cmdDetails_Click

End Sub
Nov 9 '06 #1
11 19821
pks00
280 Expert 100+
Not sure what u mean here, given a PromoCode, u want to find that record in the current form?

if thats what u mean then u could use recordsetclone and bookmarks
e.g.

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdDetails_Click()
  2.  
  3.     dim rs as dao.recordset
  4.  
  5.     set rs=me.recordsetclone
  6.     rs.findfirst "[PromoCode]=" & Me.PromoCode
  7.     if rs.nomatch=false then
  8.         me.bookmark = rs.bookmark
  9.     else
  10.         msgbox "not found"
  11.     end if
  12.  
  13.     rs.close
  14.     set rs=nothing
  15. end sub
  16.  
Nov 9 '06 #2
Thanks, I will try it.
maili
Nov 10 '06 #3
I'm having a similar problem. I am programing a Contact Management database for a friend and one of the problems I am encountering is the one described above.

I have successfully accomplished this operation in another Prospecting database I have written. In that database I use a macro to OpenForm with the Condition set to [ID]=[Forms]![ID].

This switches between two different prospecting forms generating from different Queries which hit the same two Tables.

I tried to use the same syntax in the Contact Management database when going from the Main Form, which references all the fields in the main Table, to a secondary Form, which references only the fields in a second Table.

The link between the two tables is a "Lookup Column" which pulls the first and last names of agents from the secondary table.

I want to use this Lookup Column entry in the Main form to open a secondary form bound to the secondary database and selecting the entire record from which the Lookup Column entry was selected. I have tried the same syntax that worked in the other database but when I run the macro access pops up an entry box asking for the contents of the form field which contains the Lookup Column value.

1. Is it possible to use the value in a Lookup Column as a table to table link in this fashion?
2. What is the proper syntax to accomplish this?

My SQL skills are very rusty so I am using the wizars where ever possible.

thanks
dave
Nov 11 '06 #4
Correction to my previous post. The 'Where Condition' statement is [ID]=[Forms]![referring form name]![ID].

[ID] is the key field. I believe I am seeing something; the statement after the = is the key field (the field linking the two forms) in the Form you are using for the source of the data and the [ID] before the = referrs to the cooresponding field in the target Form.

Is this correct?
Nov 11 '06 #5
It worked!

The syntax that worked is [target field name]=[Forms]![originating form]![originating field name]. Where the value in the 'Originating Field' and the 'Target Field' are to be equal.

Thank you all. Reading your input in the previous posts in this thread helped get my thinking going in the right direction.

The full method I used is this:

Go to Macros;
Create a new macro;
In the 'Actions Column' select 'OpenForm' from the drop down list;
In the 'Action Arguments' section at the bottom of the screen, on the 'Form Name' line select the Target Form from the drop down list;
On the 'Condition is' line enter the SQL statement above.
In Comand Button creation select 'Miscelaneous' - Run Macro - (your new macro name) from the list.

I found that when the Originating Form field is a 'Lookup Column' referencing a field in the Secondary Table, The correct 'Target Field' is the [ID] field since that is the numeric value stored in 'Lookup Column' field in the Originating Form.

Hope this helps.
Nov 11 '06 #6
PEB
1,418 Expert 1GB
Hi if your promocode is a text so the line :
stLinkCriteria = "[PromoCode]=" & Me![PromoCode]

Should be:
stLinkCriteria = "[PromoCode]='" & Me![PromoCode] &"'"


Hi All,
I have a cmd button "Details" on a form listing all available records; how do I direct it to the selected record rather than just open a form?
Below is the code for Open the form I have so far. Thanks for the help!
maili
================================
Private Sub cmdDetails_Click()
On Error GoTo Err_cmdDetails_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "PromosMainForm"

stLinkCriteria = "[PromoCode]=" & Me![PromoCode]
DoCmd.OpenForm stDocName, , stLinkCriteria

Exit_cmdDetails_Click:
Exit Sub

Err_cmdDetails_Click:
MsgBox Err.Description
Resume Exit_cmdDetails_Click

End Sub
Nov 11 '06 #7
It worked!
I tried the Macro, it worked. However I need the vb code, so I tried the code.
(Also, there is a process to convert Macro into vb:
Go to the macro u want to convert
click on Tools on menu bar,
choose Macro, convert to visual basic)

They are both working.
Thank you all.
Cheers
Nov 14 '06 #8
NeoPa
32,556 Expert Mod 16PB
It worked!
I tried the Macro, it worked. However I need the vb code, so I tried the code.
(Also, there is a process to convert Macro into vb:
Go to the macro u want to convert
click on Tools on menu bar,
choose Macro, convert to visual basic)


They are both working.
Thank you all.
Cheers
That is brilliant - I wish I'd known that all these years.
It's a bit late for me now but using that is a very good way to start learning about VBA in Access and especially the common library routines.
(D*mn - I wish I'd known that before!)
Thanks for that Mailing.

-Adrian.
Nov 14 '06 #9
MMcCarthy
14,534 Expert Mod 8TB
That is brilliant - I wish I'd known that all these years.
It's a bit late for me now but using that is a very good way to start learning about VBA in Access and especially the common library routines.
(D*mn - I wish I'd known that before!)
Thanks for that Mailing.

-Adrian.
Hey Adrian

I knew but I wasn't going to let you into all my secrets now was I.

Actually it's been so long since I used macros for anything. IT managers hate them as they are so hard to maintain. I prefer to use code myself anyway.

Mary
Nov 15 '06 #10
NeoPa
32,556 Expert Mod 16PB
Don't get me wrong Mary - I'm 100% with you on that.
I was thinking that, for a beginner (I wish I'd known back then for myself), learning which procedures and objects are available in the main libraries, and some of the basic forms that code takes, can be a real boost to getting going in a language.
I started from scratch in Excel and was helped enormously then by recording macros, which I then checked out in the VBA window.
You get the system to create code for a job which you know, then peruse the code until you understand what it's doing.
Nov 15 '06 #11
MMcCarthy
14,534 Expert Mod 8TB
Don't get me wrong Mary - I'm 100% with you on that.
I was thinking that, for a beginner (I wish I'd known back then for myself), learning which procedures and objects are available in the main libraries, and some of the basic forms that code takes, can be a real boost to getting going in a language.
I started from scratch in Excel and was helped enormously then by recording macros, which I then checked out in the VBA window.
You get the system to create code for a job which you know, then peruse the code until you understand what it's doing.
I agree completely. I really just meant that is has been so long since I'd used macros that I had forgotton the macro to code feature existed. My problem now days is when someone asks me a macro question I can't remember the syntax and I have to check it out.

Mary
Nov 15 '06 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: deko | last post by:
I have a form with a subform datasheet - I need code behind the OnDelete event of the subform: Private Sub Form_Delete(Cancel As Integer) 'do something that depends on which record is deleted...
7
by: ChrisR | last post by:
Hi guys My app is a simple Main form with a few Subforms that are not linked, and a few pop forms. Problem is: I have a pop form with a Listbox with a list of records related to the...
2
by: David | last post by:
Hi, I have an order form which has a field 'ProductID'. This form has a button on each record to open a new form linked by ProductID. This new form is a continuous form and obviously, only...
8
by: Zlatko Matić | last post by:
There is a form (single form) and a combobox. I want that current record of the form is adjusted according to selected value in the combobox. Cuurrent record should be the same as the value in the...
4
by: acni | last post by:
I have the following peice of code to try and send an email to selected contacts in my form.The problem is this line: StrStore = DLookup("", "qrySelectEmail", "??????") This looks up the email...
2
by: dbuchanan | last post by:
Hello, I want to open a child form based on the record selected in a dataGridView of the parent form. I want the child form to open with a populated child table based on the selected parent...
3
by: Brian Tkatch | last post by:
I have a form with two DataGrids, which are kept in sync manually via Stored PROCEDURE calls. That is, when a record is selected on the first grid, a stored PROCEDURE is CALLed to Fill() the next...
5
by: juengelj | last post by:
I have four listboxes on my form. When I add a new record, I run the following code to clear list box items... Public Function ClearAll() 'This function clears ALL selected fields in the form's...
1
by: angelicdevil | last post by:
i have listbox 1 which displays status , based on selection of status listbox 2 displays usernames. and based on username selected the textbox displays the email id. its working fine till...
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
BarryA
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...
1
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...
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
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,...
0
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...
0
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,...
0
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...
0
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...

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.