|
-
Feb 28th, 2002, 04:25 AM
#1
Thread Starter
Lively Member
What the....
I have an add button on my main form, when I press this "add" button I want to be able to open a form which has textboxes that are linked to my datacontrol, so this 2nd form will be my data entry form. I would like the textboxes to be empty(and ready to add data into) so i tried to add this line of code to the 2nd form's load event: Form2.Data1.recordset.Addnew but it keeps coming up with this error:
Runtime error"91" Object variable or With Block variable not set
I'm using vb5 by the way,
What am I doing wrong??
Thanks,
-
Feb 28th, 2002, 04:29 AM
#2
Addicted Member
Form2!Data1.recordset.addnew
If your calling doing this procedure from another form use the exclamation
-
Feb 28th, 2002, 04:52 AM
#3
Hmmmm...Meeting, think I'm missing it :)
Use a !....why?
I absolutely destest bound controls
-
Feb 28th, 2002, 05:05 AM
#4
Thread Starter
Lively Member
I just tried what you said, Javan, but I still got the same error message,
any other ideas?
-
Feb 28th, 2002, 05:13 AM
#5
Same code, same jokes, same carrot?
From the test I have just done, it's impossible to bind a control from on form to a data control on another 
Have you set up your data control correct, since that error points to an object, within the data control, which is trying to be referenced, but has not been set up. ie Is your control looking at a table in a database?
-
Feb 28th, 2002, 05:49 AM
#6
Member
what is the backend u r using?at design time did u set all data source properties of the data1.....i think u r setting datasource of data1 at runtime without the keyword 'set'
if u want say..what is the properties u have set to data1...
then we see...
i think u will not get the result by using that data1control on the same form also...check it once whether that is comming properly on the same form or not.....
-
Feb 28th, 2002, 06:38 AM
#7
Thread Starter
Lively Member
Ok, Thanks guys, Iv'e pretty much got that part sorted(I ditched the data bound control for dao) but I'd still like to open Form2 with cleared textboxes. (the textbox now opens with the first record in it)
Is there a way to open Form2 with all the textboxes being empty(so when Form2 loads, you dont have to press a button to clear them?)
Thanks in advance,
-
Feb 28th, 2002, 06:46 AM
#8
Personally I would use ADO, buy hey, each to there own.
Couldn't you put the code to clear the text boxes, in the Form_Load event?
U still using bound controls?
or have:
VB Code:
Public Funtion Clear()
Text1.text=vbNullstring
'Blah, Blah, Blah
End Function
In Form2 and in the procedure, in form which you load form2 from, have:
VB Code:
Dim frmNew As Form2
Set frmNew = New Form2
Load frmNew
frmNew.Clear
frmNew.Show vbModal, Me
?
-
Feb 28th, 2002, 10:50 PM
#9
Thread Starter
Lively Member
Thanks for the help, I've sorted out the clearing of the textboxes,
but how do i move to the last record in the database, because now that the textbox is cleared and you type in a name, it replaces the first entry in the database. I've tried this:
Private Sub Form_Load()
Dim rs As Recordset
Dim ws As Workspace
Dim db As Database
Set ws = DBEngine.Workspaces(0)
Set db = ws.OpenDatabase("C:\Program Files\DevStudio\VB\ZTest1.mdb")
rs.MoveLast
End Sub
Thats in Form2's Load event and i get an error:
Runtime error "91": Object Variable or With block variable not set
rs.Movelast is highlighted
What does this mean?
Thanks...
-
Mar 1st, 2002, 03:41 AM
#10
Fidos dinner is not for humans to eat!
Rs has not been initialized, sorry if thats the incorrect terminology 
Here's some example code?
VB Code:
Sub AddNewX()
Dim dbsNorthwind As Database
Dim rstEmployees As Recordset
Dim strFirstName As String
Dim strLastName As String
Set dbsNorthwind = OpenDatabase("Northwind.mdb")
Set rstEmployees = _
dbsNorthwind.OpenRecordset("Employees", dbOpenDynaset)
' Get data from the user.
strFirstName = Trim(InputBox( _
"Enter first name:"))
strLastName = Trim(InputBox( _
"Enter last name:"))
' Proceed only if the user actually entered something
' for both the first and last names.
If strFirstName <> "" and strLastName <> "" Then
' Call the function that adds the record.
AddName rstEmployees, strFirstName, strLastName
' Show the newly added data.
With rstEmployees
Debug.Print "New record: " & !FirstName & _
" " & !LastName
' Delete new record because this is a demonstration.
.Delete
End With
Else
Debug.Print _
"You must input a string for first and last name!"
End If
rstEmployees.Close
dbsNorthwind.Close
End Sub
Function AddName(rstTemp As Recordset, _
strFirst As String, strLast As String)
' Adds a new record to a Recordset using the data passed
' by the calling procedure. The new record is then made
' the current record.
With rstTemp
.AddNew
!FirstName = strFirst
!LastName = strLast
.Update
.Bookmark = .LastModified
End With
End Function
-
Mar 2nd, 2002, 07:21 PM
#11
Thread Starter
Lively Member
Thanks Wokawidget your Da Man,
One more thing please,. In this line:AddName rstEmployees, strFirstName, strLastName, how do I add an entry for a phone number?
Ta
-
Mar 2nd, 2002, 08:01 PM
#12
Thread Starter
Lively Member
Forget about the last post, I've worked it out,
Though, how do I copy the contents of a textbox,(say someone types their name into a textbox) into the first inputBox that pops up, or is there a way to do this?
Thanks again,
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|