Wrox Programmer Forums
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 16th, 2007, 10:15 AM
Authorized User
 
Join Date: Apr 2007
Posts: 65
Thanks: 0
Thanked 0 Times in 0 Posts
Default Open Task

I've created a form where the user will enter a known "Task_ID" number, ie: 18 (unbound text box). They then click a command button "Open Task" and the task, on frmTask, should then be opened for the user to edit or add to with data.

Both of the forms are designed but I can't figure out the code to get the command button (Open Task) to look at the data that is entered into the unbound textbox (Task_ID) to then open it.

 
Old May 16th, 2007, 08:06 PM
Registered User
 
Join Date: May 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to zaqyu
Default

Plase try this:

Docmd.OpenForm "[name of the form you'll open]",,,"[taskid] =" & me.Task_ID



 
Old May 17th, 2007, 09:56 AM
Authorized User
 
Join Date: Apr 2007
Posts: 65
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok, I tried that. the only thing it does is open the first record on the correct form, it DOES NOT open the selected/desired/entered Task_ID that is entered into the text box (txtTask.Text).

Code on the command button is:

DoCmd.OpenForm "frmTask", acNormal, , , acFormEdit, acDialog, txtTask.Text = ""
DoCmd.Close acForm, Me.Name, acSaveNo

 
Old May 17th, 2007, 11:30 AM
Friend of Wrox
 
Join Date: Feb 2007
Posts: 163
Thanks: 0
Thanked 2 Times in 2 Posts
Default

I usually use .value instead of .text myself. You may want to check and see if the .text isn't being formatted so it doesn't actually match.

If you're still not getting to the record you want, try the below instead.

From your button:
-----------------------------------------
Private Sub Your_Button_Click()

'Opens Form and sends desired value to form
  DoCmd.OpenForm "frmTask", acNormal
  Call Forms("frmTask").DoFind(txtTask.Value) 'I'm using .value, use .text if you want and it's not different

End Sub
-----------------------------------------

Then create a public sub in frmTask:

If the table value is a string:
-----------------------------------------
Public Sub DoFind(sToFind As String)

'Finds record where Task_ID is passed value allowing other forms to change record
  Me.Recordset.FindFirst("Task_ID = """ & sToFind & """")

End Sub
-----------------------------------------

If the table value is an Integer:
-----------------------------------------
Public Sub DoFind(iToFind As Long)

'Finds record where Task_ID is passed value allowing other forms to change record
  Me.Recordset.FindFirst("Task_ID = " & iToFind)

End Sub
-----------------------------------------

Note: If it's a number but NOT an Integer then change variable to Double type instead of Long type

Just to be complete, If the table value is a Date/Time field:
-----------------------------------------
Public Sub DoFind(dToFind As Date)

'Finds record where Task_ID is passed value allowing other forms to change record
  Me.Recordset.FindFirst("Task_ID = #" & dToFind & "#")

End Sub
-----------------------------------------

Hope this helps get it to work.

 
Old May 17th, 2007, 04:12 PM
Authorized User
 
Join Date: Apr 2007
Posts: 65
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I got a 'Error 424' on the first part of calling the form.

 
Old May 22nd, 2007, 05:35 AM
Friend of Wrox
 
Join Date: Apr 2006
Posts: 159
Thanks: 0
Thanked 0 Times in 0 Posts
Default

An other way to do this is to make a sql-string first when you press the action button and give this string to the on load event of the second form, so you can only have 1 record shown, since your second form will have a query behind it...

If you still need this, let me know and I'll try the post more details if needed.

 
Old May 22nd, 2007, 08:18 AM
Authorized User
 
Join Date: Apr 2007
Posts: 65
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Vince,

Yeah, I'm still trying to figure this out. I had it one time where it would open the form, or call it, but it wouldn't look for the data that was in the txt box, txtTask.text, which held the number of the task that the user specified.

I'm just trying to have the user put in the desired number, say "21", into the text box named, txtTask.text. Then the user clicks on a command button, named "cmdFind", and it pulls the form and the corresponding record with all data into the form, called frmTask.

 
Old May 22nd, 2007, 10:11 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Two ways to do this.

Dim iTask As Integer
Dim sDoc, sLink As String

iTask = Me.TaskID
sLink = "[TaskID] = " & iTask

DoCmd.OpenForm sDoc, acNormal, , sLink

The other way is useful if the form is based on a query. It it is, I will post that code, since it is easier, but you can only use the query for the one form.

HTH


mmcdonal
 
Old May 22nd, 2007, 10:14 AM
Authorized User
 
Join Date: Apr 2007
Posts: 65
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks mmcdonal. Appreciate it.






Similar Threads
Thread Thread Starter Forum Replies Last Post
How to add task in Scheduled Task programatically amitjoshipune C# 2 July 31st, 2008 05:42 AM
Open document, Open second doc and copy to first justabeginner Word VBA 1 March 7th, 2007 02:47 AM
Open the "Open File" dialogue box piratelordx Access VBA 4 March 14th, 2006 10:08 PM
Execute Task from ActiveX Script Task PorcupineRabbit SQL Server DTS 1 January 10th, 2006 12:37 PM
Task Name hortoristic SQL Server DTS 4 June 21st, 2005 01:52 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.