Results 1 to 12 of 12

Thread: What the....

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Location
    Sydney, Australia
    Posts
    118

    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,

  2. #2
    Addicted Member
    Join Date
    Feb 2002
    Posts
    242
    Form2!Data1.recordset.addnew

    If your calling doing this procedure from another form use the exclamation

  3. #3

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Location
    Sydney, Australia
    Posts
    118
    I just tried what you said, Javan, but I still got the same error message,

    any other ideas?

  5. #5
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Talking 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?

  6. #6
    Member
    Join Date
    Feb 2002
    Location
    A.P,INDIA
    Posts
    48
    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.....
    Rojasree.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Location
    Sydney, Australia
    Posts
    118
    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,

  8. #8
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    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:
    1. Public Funtion Clear()
    2.    Text1.text=vbNullstring
    3.    'Blah, Blah, Blah
    4. End Function
    In Form2 and in the procedure, in form which you load form2 from, have:
    VB Code:
    1. Dim frmNew   As Form2
    2.    Set frmNew = New Form2
    3.    Load frmNew
    4.    frmNew.Clear
    5.    frmNew.Show vbModal, Me

    ?

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Location
    Sydney, Australia
    Posts
    118
    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...

  10. #10
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Talking 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:
    1. Sub AddNewX()
    2.  
    3.     Dim dbsNorthwind As Database
    4.     Dim rstEmployees As Recordset
    5.     Dim strFirstName As String
    6.     Dim strLastName As String
    7.  
    8.     Set dbsNorthwind = OpenDatabase("Northwind.mdb")
    9.     Set rstEmployees = _
    10.         dbsNorthwind.OpenRecordset("Employees", dbOpenDynaset)
    11.  
    12.     ' Get data from the user.
    13.     strFirstName = Trim(InputBox( _
    14.         "Enter first name:"))
    15.     strLastName = Trim(InputBox( _
    16.         "Enter last name:"))
    17.  
    18.     ' Proceed only if the user actually entered something
    19.  
    20. ' for both the first and last names.
    21.     If strFirstName <> "" and strLastName <> "" Then
    22.  
    23.         ' Call the function that adds the record.
    24.         AddName rstEmployees, strFirstName, strLastName
    25.  
    26.         ' Show the newly added data.
    27.         With rstEmployees
    28.             Debug.Print "New record: " & !FirstName & _
    29.                 " " & !LastName
    30.             ' Delete new record because this is a demonstration.
    31.             .Delete
    32.         End With
    33.  
    34.     Else
    35.         Debug.Print _
    36.             "You must input a string for first and last name!"
    37.  
    38. End If
    39.  
    40.     rstEmployees.Close
    41.     dbsNorthwind.Close
    42.  
    43. End Sub
    44.  
    45. Function AddName(rstTemp As Recordset, _
    46.     strFirst As String, strLast As String)
    47.  
    48.     ' Adds a new record to a Recordset using the data passed
    49.     ' by the calling procedure. The new record is then made
    50.     ' the current record.
    51.     With rstTemp
    52.         .AddNew
    53.         !FirstName = strFirst
    54.         !LastName = strLast
    55.         .Update
    56.         .Bookmark = .LastModified
    57.     End With
    58.  
    59. End Function

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Location
    Sydney, Australia
    Posts
    118
    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

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Location
    Sydney, Australia
    Posts
    118
    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
  •  



Click Here to Expand Forum to Full Width