Open Arguments (OpenArgs)

coyote

Registered User.
Local time
Today, 03:30
Joined
Oct 8, 2007
Messages
149
A problem worth pondering.
I have two forms
frmAspirants which takes in details of aspirants in an election
frmChequeDetails which takes the details of the cheques paid by the aspirants.

In the frmAspirants there is an option group (optPayMode) where the user selects whether its paid in cash or cheque.
When the user enters all the details and the option is check then there is a command that opens frmChequeDetails using the following code

Private Sub cmdCheque_Click()
On Error GoTo Err_cmdCheque_Click



DoCmd.OpenForm "ChequeDetails", , , , acAdd, , Me.IDNO


Exit_cmdCheque_Click:
Exit Sub

Err_cmdCheque_Click:
MsgBox Err.Description
Resume Exit_cmdCheque_Click

End Sub

Then on the OnLoad event of frmChequeDetails there is this code

Private Sub Form_Load()

Dim db As DAO.Database
Dim rst As DAO.Recordset

Set db = CurrentDb()
Set rst = db.OpenRecordset("SELECT * FROM ConstituencyAspirants WHERE [IDNO]=" & Me.OpenArgs)

If Nz(rst.RecordCount, 0) <> 0 Then
With rst
Me.IDNO = .Fields("IDNO") 'i.e. your control name would be something
'like Me.CustomerName
Me.FullName = .Fields("FullName")
Me.VoterRegistrationNo = .Fields("VoterRegistrationNo")
Me.Amount = .Fields("Amount")

End With
Else
MsgBox "This Aspirant Doesn't really exist"
End If

rst.Close
Set rst = Nothing
db.Close
Set db = Nothing


End Sub

The problems is since the data is yet to be saved am getting the message.
Also an error about the syntax in the Set rst Line.
Anyone with an idea how you can open a form with OpenArgs before the other data is saved

all help appreciated
 
If the error line stop here.
Set rst = db.OpenRecordset("SELECT * FROM ConstituencyAspirants WHERE [IDNO]=" & Me.OpenArgs)
all help appreciated

What is the Datatype for "IDNO"? You may need single quote if it is text.
 
If you are creating a record in your ChequeDetails table that will have a ForeignKey from the ConstituencyAspirants table and *that* key does not exist yet, then you are violating Referential Integrity anyway and should not do it. FWIW, all of the data from the frmAspirants form can be passed in the OpenArgs argument at the same time.
 

Users who are viewing this thread

Back
Top Bottom