Docmd.openform Problem

Belimisimus

Registered User.
Local time
Today, 21:38
Joined
Mar 30, 2010
Messages
11
Hello to everyone,
hope that someone can help me to find a solution for my problem.

I have simple database with one table (TaskID, Task name) and two forms. In first form (Task1) I add on load event code:

Code:
Private Sub  Form_Load()
    Form.RecordSource = "SELECT Tasks.* FROM Tasks;"
End  Sub


And in second form (Task2) I add on "Task name" field dbl click event code:

Code:
Private Sub  Task_Name_DblClick(Cancel As Integer)
    DoCmd.OpenForm "Tasks1", , ,  "TaskID = " & Me.TaskID, , acDialog
End Sub


So if I dbl click task name in second form, this task should be open in the first form. But it doesn't.
If I disable code in first form everything is working fine.
Obviously something is missing and I can't figure what is it.
 
1. Why are you setting the recordsource of the form via code instead of just setting it at design time?

2. Is TaskID a numeric field or a text field?
 
1. Why are you setting the recordsource of the form via code instead of just setting it at design time?

2. Is TaskID a numeric field or a text field?

wow that was fast...

1. Because I have groups of users, who is log in and depend on the group they can have access to some fields. Example:

Code:
If gbl_GrupaID = 2 Then
cbo_AssignedTo.Enabled = False
Form.RecordSource = "SELECT Tasks.* FROM Tasks WHERE AssignedTo = " & gbl_ContaktID & ";"

2. TaskID is auto number
 
I would make sure that

1. TaskID is on the second form.

2. Put a breakpoint on the code to check to make sure that the value is being passed as it looks like it should.

3. You can also try using Me!TaskID like this (and shorten it using the arguments instead of the commas):

DoCmd.OpenForm "Tasks1", WhereCondition:="[TaskID]=" & Me!TaskID, WindowMode:= acDialog
 
Try saving the Task ID first
 
1. This two forms are the simplest form I could make for example. Both have TaskID and Task name and both are related to table "Tasks"
2. I'm not sure how to do that (sorry still learning) but as you say value should be pass
3. Have try, still not working


I'm trying this for almost two days and still can't find a solution...
 
1. This two forms are the simplest form I could make for example. Both have TaskID and Task name and both are related to table "Tasks"
2. I'm not sure how to do that (sorry still learning) but as you say value should be pass
3. Have try, still not working


I'm trying this for almost two days and still can't find a solution...

Can you upload a copy of the database (with bogus data of course). If you need a quick tool to clear all of the data out so you can enter some fake stuff in, check out Bob Larson's Database Reset Tool on this page here.
 
Can you upload a copy of the database (with bogus data of course). If you need a quick tool to clear all of the data out so you can enter some fake stuff in, check out Bob Larson's Database Reset Tool on this page here.

Thx I'll check, here is the database
 

Attachments

It works fine for me (see the attached file). If not, what service pack are you on? I am on Office 2007 SP3.
 

Attachments

It works fine for me (see the attached file). If not, what service pack are you on? I am on Office 2007 SP3.


The same, I have also try this in win7 Office 2010 Beta and the same thing!

Are you sure it's working? I see that you have add dbl click code in form1. I want to form1 is open from form 2. Try opening "bbb" or "ccc" task from form Task2 with my code!!!
 
Okay, the problem IS that code in the On Load event of the form. You would need to not use it when using the double click. So you can pass OpenArgs to tell it not to use it. See the attachment.
 

Attachments

Okay, the problem IS that code in the On Load event of the form. You would need to not use it when using the double click. So you can pass OpenArgs to tell it not to use it. See the attachment.

Thx for helping me....
:) you can't believe how happy I am to see it's actually working. Only is there a chance how can I preserve Form.RecordSource from load event? See the original code

Code:
Private Sub Form_Load()
        If gbl_GrupaID = 2 Then 'Grafika
            cbo_AssignedTo.Enabled = False
            Command_AssignedTo.Visible = True
            cboGoToContact.RowSource = "SELECT Poslovi.PosloviID, Poslovi.[Ime posla] FROM Poslovi WHERE AssignedTo = " & gbl_KontaktID & " ORDER BY Poslovi.[Ime posla];"
            Form.RecordSource = "SELECT Poslovi.*, tbluVrstaizdanja.[Vrsta izdanja], tbluObrazovanje.Obrazovanje, Izdanja.Razred, tbluPredmet.Subject, Izdanja.Autori, Izdanja.IzdanjeID, Kontakti.ContactID FROM tbluPredmet INNER JOIN (tbluObrazovanje INNER JOIN ((tbluVrstaizdanja INNER JOIN (Izdanja INNER JOIN Poslovi ON Izdanja.IzdanjeID=Poslovi.[Vezano uz izdanje]) ON tbluVrstaizdanja.[Vrsta izdanjaID]=Izdanja.[Vrsta izdanja]) INNER JOIN Kontakti ON Poslovi.AssignedFrom=Kontakti.ContactID) ON tbluObrazovanje.ObrazovanjeID=Izdanja.Obrazovanje) ON tbluPredmet.SubjectID=Izdanja.Predmet WHERE AssignedTo = " & gbl_KontaktID & ";"
        ElseIf gbl_GrupaID = 3 Then 'Uredništvo
            cbo_AssignedFrom.Enabled = False
            Command_AssignedFrom.Visible = True
            cbo_AssignedTo.Enabled = False
            Command_AssignedTo.Visible = True
            cboGoToContact.RowSource = "SELECT Poslovi.PosloviID, Poslovi.[Ime posla] FROM Poslovi WHERE AssignedFrom = " & gbl_KontaktID & " ORDER BY Poslovi.[Ime posla];"
            Form.RecordSource = "SELECT Poslovi.*, tbluVrstaizdanja.[Vrsta izdanja], tbluObrazovanje.Obrazovanje, Izdanja.Razred, tbluPredmet.Subject, Izdanja.Autori, Izdanja.IzdanjeID, Kontakti.ContactID FROM tbluPredmet INNER JOIN (tbluObrazovanje INNER JOIN ((tbluVrstaizdanja INNER JOIN (Izdanja INNER JOIN Poslovi ON Izdanja.IzdanjeID=Poslovi.[Vezano uz izdanje]) ON tbluVrstaizdanja.[Vrsta izdanjaID]=Izdanja.[Vrsta izdanja]) INNER JOIN Kontakti ON Poslovi.AssignedFrom=Kontakti.ContactID) ON tbluObrazovanje.ObrazovanjeID=Izdanja.Obrazovanje) ON tbluPredmet.SubjectID=Izdanja.Predmet WHERE AssignedFrom = " & gbl_KontaktID & ";"
        Else
        End If
End Sub

gbl_GrupaID is the global variable which holds the Current Group and gbl_KontaktID is the global variable which holds the Current User who is logged on.

I'm trying to get the following, if someone from group "2" opens the task form via swichboard manager or via dbl click i would like to preserve the necessary RecordSource for that particular group. The same thing is for group "3"
 
No, you can't use the load event when you use that filtering. BUT you CAN have the generic recordsource set and then use MORE filters to filter based on what you would NORMALLY use in that load event.
 
Ok i give up for today, thx for your help and time. If nothing else I know in which direction I must go with the further development of a database.
Thx again!
 

Users who are viewing this thread

Back
Top Bottom