Question : DoCmd.OpenForm Question

Hi Experts,

I am really confused on how to use DoCmd.OpenForm.  

Assuming the following:

Form A, bound to TableA with PrimaryKeyA.

I would like to click a command button CMD_A and open Form B, bound to TableJunctionB with PrimaryKeyA.

In other words, if a record already exists in TableJunctionB with PrimaryKeyA, FormB would filter to that record.

Otherwise, FormB would open to a new record with the current PrimaryKeyA from FormA TableA fed into FormB and TableJunctionB.

From what I have read, open arguments allows alot of versatility, however, I can't understand the examples.  I haven't been able to develop a solution for weeks.  So I am trying to break up my question and start off with the main issue to see if I can add in other elements.  I'm not going to post the code I have been working on because everytime I do, I can't seem to get answers that make my code work.  I'm hoping that somebody can point me to an example where these basics are explained.

Frustrated with Access and the flu,

Newbie

Answer : DoCmd.OpenForm Question

The CreateAndTestQuery procedure referenced in the above code is listed below:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
Public Function CreateAndTestQuery(strTestQuery As String, _
   strTestSQL As String) As Long
'Created by Helen Feddema 28-Jul-2002
'Last modified 13-Aug-2008
 
On Error Resume Next
   
   Dim qdf As DAO.QueryDef
   
   'Delete old query
   Set dbs = CurrentDb
   dbs.QueryDefs.Delete strTestQuery
 
On Error GoTo ErrorHandler
   
   'Create new query
   Set qdf = dbs.CreateQueryDef(strTestQuery, strTestSQL)
   
   'Test whether there are any records
   Set rst = dbs.OpenRecordset(strTestQuery)
   With rst
      .MoveFirst
      .MoveLast
      CreateAndTestQuery = .RecordCount
   End With
   
ErrorHandlerExit:
   Exit Function
 
ErrorHandler:
   If Err.Number = 3021 Then
      CreateAndTestQuery = 0
      Resume ErrorHandlerExit
   Else
      MsgBox "Error No: " & Err.Number & "; Description: " & Err.Description
      Resume ErrorHandlerExit
   End If
   
End Function
Random Solutions  
 
programming4us programming4us