Comaparing user input value from form to values stored in a Db Column

englishkid19

Board Regular
Joined
Nov 14, 2012
Messages
89
Hi All,
This must have been covered before : looking for pointers please .

I have a userform with an "Add Button/Submit".

The user populates 5 to 6 text and number boxes then clicks submit. I have that all working and it adds records to the db.

The part i need help with is an UPDATE statment. so if a user makes errors in there initial submission , i want them to be able to UPDATE the record they have entered....

So essentially it needs to be something like this :

IF Me.DateBox.Value & Me.ResourceBase.Value = Input.DateAdded & Input.ResourceBase = TRUE
<<so it compares the date & resourcebase against dates and resource base combinations in the table >>
THEN
" Execute my update statement"
ELSE IF
Evaluate next row of database
<< i could probably do with another statment like " The combination of resource base and date you are trying to update are not present in table >>
END IF

any pointers greatlly appreciated
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Why not just bind the form?

Hi All,
This must have been covered before : looking for pointers please .

I have a userform with an "Add Button/Submit".

The user populates 5 to 6 text and number boxes then clicks submit. I have that all working and it adds records to the db.

The part i need help with is an UPDATE statment. so if a user makes errors in there initial submission , i want them to be able to UPDATE the record they have entered....

So essentially it needs to be something like this :

IF Me.DateBox.Value & Me.ResourceBase.Value = Input.DateAdded & Input.ResourceBase = TRUE
<<so it="" compares="" the="" date="" &="" resourcebase="" against="" dates="" and="" resource="" base="" combinations="" in="" table="">>
THEN
" Execute my update statement"
ELSE IF
Evaluate next row of database
<< i could probably do with another statment like " The combination of resource base and date you are trying to update are not present in table >>
END IF

any pointers greatlly appreciated

</so>
 
Upvote 0
A couple of things:
1) you don't need "=TRUE" in the IF statement - the expression xxx=yyy will return true or false, which the IF statement will process
2) If your form is bound to a table (INPUT?), your code will only compare the user entry to the CURRENT RECORD associated with the form. More importantly, the second the user starts typing in the bound textboxes, Access will be creating an pending update for the current record, which is not what you want. In order to enable update, you need a search function; if the form is bound to a table, you probably want to have 2 unbound input boxes for DateBox and ResourceBase, then trigger a search after the user enters those 2 fields. If the matching record is found, make it the current record and display the values in the form. Once the user updates the values, you'll fire an update statement when the submit button is pressed. You might need to set a boolean flag to indicate whether to do an update or an insert. If a matching record is NOT found, populate the 2 fields in a new record with the user input, then let the user complete the form and fire an insert when the submit button is pressed.
3) To facilitate the search, create a UNIQUE index on the underlying table which contains DateAdded and ResourceBase. This will prevent the creation of duplicate records and make the search process much faster.
 
Upvote 0

Forum statistics

Threads
1,221,773
Messages
6,161,855
Members
451,724
Latest member
sledparty

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top