new entry in table

human_anomaly

Registered User.
Local time
Today, 15:59
Joined
Apr 12, 2004
Messages
69
I have an input box that gets a string from the user. I want to put that string in a table. How would I do that?
 
You might need a reference to DAO. Or you can convert the code from DAO to ADO if desired.

Code:
Const TableName As String = "MyTable"
Const FieldName As String = "MyField"

Const InputMessage As String = "Please enter a value"
Const InputTitle As String = "Enter Value"

Dim DataString As String
Dim db As DAO.Database
Dim rs As DAO.Recordset

Do While DataString <> vbNullString
    DataString = InputBox(InputMessage, InputTitle)
Loop

Set db = CurrentDb
Set rs = db.OpenRecordset(TableName)
    With rs
        .AddNew
        .Fields(FieldName) = DataString
        .Update
        .Close
    End With

Set rs = Nothing
Set db = Nothing
 
It isn't finding the DAO object. Could this be because my database is a .adp (Access Data Project)? or do I need to include something in my code?
 
thanks that solved the DAO problem but now but the "set db =" is not working. can you provide an example of how to tell it to use the current database?
 

Users who are viewing this thread

Back
Top Bottom