Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to pass Information to an unbound Form 1

Status
Not open for further replies.

HappyRed

Programmer
Mar 22, 2005
9
US

I will place this question both in the Forms and the Table Forum because I am not sure where should it be.

I am trying to do a payment calendar, sort of a What if scenario.

My form has 3 fields. Customer ID, Amount to pay and Number of payments.

Based on this information I have to create a bunch of fields, each one which is a payment date and amount.

The Form has to be unbound at the beginning. After I capture the data, I calculate the payments programatically, which I can.

I also opened a recordset that has the data.

What I am missing is how to connect these data back to the form.

This is my code

Set cnn1 = New ADODB.Connection

With cnn1
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionString = CurrentProject.Path & "\credito_App.mdb"
.Open
End With

Set rsCust = New ADODB.Recordset
rsCust.CursorType = adOpenKeyset
rsCust.LockType = adLockOptimistic

rsCust.Open "Calendar", cnn1

With rsClientes
' With frm1
.AddNew

' Save Data to DB

.Fields("IDnumber").Value = Me.FindCust
.Fields("Payments").Value = Me.Payments
.Fields("Total").Value = Me.Total

m = Me.Payments
For j = 1 To m
nextrec = recname + Trim(Str(j))
MsgBox ("I will save" + " " + nextrec)

.Fields(nextrec).Value = Amount

Next j
.Requery

End With

When I look into the Database the new record is not there and I don't know how to connect this new record to the Form since the Form is unbound. DO i Need to have two identical Forms one bound and the other unbound and here switch to the other form?

I will greatly appreciate the input.



 
1)
rsCust.Open "Calendar", cnn1
With rs[highlight]Cust[/highlight]
2)
.Update instead of .Requery

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Another "trick" is to change the RecordSource of the form.

You either manipulate the RecordSource from the another form, or pass the RecordSource in the OpenArgs property when calling the form.

The cool thing with this type of approach is that you let the Access form wizard create the form (based on a table or query), and then delete the RecordSource property for the form.

Then on the OnLoad or OnOpen event procedure, assuming the OpenArgs is an SQL query string...
Code:
If Len(Me.OpenArgs & "") Then
   Me.RecordSource = Me.OpenArgs
   Me.Requery
End If

You could also just pass the primary key in the OpenArgs and then build your query...

Code:
Dim strSQL as String

strSQL = "SELECT * FROM tblCalendar"

If Nz(Me.OpenArgs, 0) Then
   strSQL = strSQL & " WHERE FindCust = " & IDnumber
   Me.RecordSource = strSQL
   Me.Requery
End If

Richard
 
Thank you Richard this look much too cool.

This will help me to kill two birds with one stone, because once I had this part working I needed to be able to go only to the specific record that I just created and not ot the first record which is what happens when you just open a form the first time.

Thanks much!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top